Skip to content

Commit 6a0ad54

Browse files
committed
bless tests
1 parent 1691591 commit 6a0ad54

File tree

11 files changed

+600
-110
lines changed

11 files changed

+600
-110
lines changed

crates/bevy_mod_scripting_bindings/src/docgen/info.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ variadics_please::all_tuples!(impl_documentable, 0, 13, T);
229229

230230
#[cfg(test)]
231231
mod test {
232+
use bevy_mod_scripting_bindings_domain::ReflectionPrimitiveKind;
233+
232234
use crate::{
233235
docgen::typed_through::UntypedWrapperKind,
234236
function::from::{Mut, Ref, Val},
@@ -252,15 +254,15 @@ mod test {
252254
assert_eq!(info.arg_info[1].type_id, TypeId::of::<f32>());
253255

254256
match info.arg_info[0].type_info.as_ref().unwrap() {
255-
ThroughTypeInfo::TypeInfo(type_info) => {
256-
assert_eq!(type_info.type_id(), TypeId::of::<i32>());
257+
ThroughTypeInfo::Primitive(prim) => {
258+
assert_eq!(*prim, ReflectionPrimitiveKind::I32);
257259
}
258260
_ => panic!("Expected TypeInfo"),
259261
}
260262

261263
match info.arg_info[1].type_info.as_ref().unwrap() {
262-
ThroughTypeInfo::TypeInfo(type_info) => {
263-
assert_eq!(type_info.type_id(), TypeId::of::<f32>());
264+
ThroughTypeInfo::Primitive(prim) => {
265+
assert_eq!(*prim, ReflectionPrimitiveKind::F32);
264266
}
265267
_ => panic!("Expected TypeInfo"),
266268
}

crates/bevy_mod_scripting_bindings/src/docgen/typed_through.rs

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -342,80 +342,54 @@ variadics_please::all_tuples!(impl_through_typed_tuple, 0, 13, T);
342342
mod test {
343343
use super::*;
344344

345-
fn assert_type_info_is_through<T: Typed + TypedThrough>() {
345+
fn assert_type_info_is_primitive<T: Typed + TypedThrough>(kind: ReflectionPrimitiveKind) {
346346
let type_info = T::type_info();
347347
let through_type_info = T::through_type_info();
348-
349-
match through_type_info {
350-
ThroughTypeInfo::TypeInfo(info) => {
351-
assert_eq!(info.type_id(), type_info.type_id());
352-
assert_eq!(info.type_path(), type_info.type_path());
353-
}
354-
_ => panic!("Expected ThroughTypeInfo::TypeInfo"),
355-
}
356-
}
357-
358-
fn assert_dynamic_through_type_is_val_info<T: Typed + TypedThrough>() {
359-
let type_info = T::type_info();
360-
let through_type_info = into_through_type_info(type_info);
361-
362-
match through_type_info {
363-
ThroughTypeInfo::UntypedWrapper {
364-
through_type,
365-
wrapper_kind,
366-
} => {
367-
assert_eq!(wrapper_kind, UntypedWrapperKind::Val);
368-
assert_eq!(through_type.type_id(), type_info.type_id());
369-
assert_eq!(through_type.type_path(), type_info.type_path());
348+
let dynamic_through_type_info = into_through_type_info(type_info);
349+
350+
for (test, info) in [
351+
("static", through_type_info),
352+
("dynamic", dynamic_through_type_info),
353+
] {
354+
match info {
355+
ThroughTypeInfo::Primitive(prim) => {
356+
assert_eq!(
357+
prim,
358+
kind,
359+
"expected {} to have primitive {test} type info: {kind}",
360+
std::any::type_name::<T>()
361+
)
362+
}
363+
_ => panic!("Expected ThroughTypeInfo::TypeInfo"),
370364
}
371-
_ => panic!("Expected ThroughTypeInfo::TypeInfo"),
372365
}
373366
}
374367

375368
#[test]
376369
fn test_typed_through_primitives() {
377-
assert_type_info_is_through::<bool>();
378-
assert_dynamic_through_type_is_val_info::<bool>();
379-
assert_type_info_is_through::<i8>();
380-
assert_dynamic_through_type_is_val_info::<i8>();
381-
assert_type_info_is_through::<i16>();
382-
assert_dynamic_through_type_is_val_info::<i16>();
383-
assert_type_info_is_through::<i32>();
384-
assert_dynamic_through_type_is_val_info::<i32>();
385-
assert_type_info_is_through::<i64>();
386-
assert_dynamic_through_type_is_val_info::<i64>();
387-
assert_type_info_is_through::<i128>();
388-
assert_dynamic_through_type_is_val_info::<i128>();
389-
assert_type_info_is_through::<u8>();
390-
assert_dynamic_through_type_is_val_info::<u8>();
391-
assert_type_info_is_through::<u16>();
392-
assert_dynamic_through_type_is_val_info::<u16>();
393-
assert_type_info_is_through::<u32>();
394-
assert_dynamic_through_type_is_val_info::<u32>();
395-
assert_type_info_is_through::<u64>();
396-
assert_dynamic_through_type_is_val_info::<u64>();
397-
assert_type_info_is_through::<u128>();
398-
assert_dynamic_through_type_is_val_info::<u128>();
399-
assert_type_info_is_through::<f32>();
400-
assert_dynamic_through_type_is_val_info::<f32>();
401-
assert_type_info_is_through::<f64>();
402-
assert_dynamic_through_type_is_val_info::<f64>();
403-
assert_type_info_is_through::<usize>();
404-
assert_dynamic_through_type_is_val_info::<usize>();
405-
assert_type_info_is_through::<isize>();
406-
assert_dynamic_through_type_is_val_info::<isize>();
407-
assert_type_info_is_through::<String>();
408-
assert_dynamic_through_type_is_val_info::<String>();
409-
assert_type_info_is_through::<PathBuf>();
410-
assert_dynamic_through_type_is_val_info::<PathBuf>();
411-
assert_type_info_is_through::<OsString>();
412-
assert_dynamic_through_type_is_val_info::<OsString>();
413-
assert_type_info_is_through::<char>();
414-
assert_dynamic_through_type_is_val_info::<char>();
415-
assert_type_info_is_through::<ReflectReference>();
416-
assert_dynamic_through_type_is_val_info::<ReflectReference>();
417-
assert_type_info_is_through::<&'static str>();
418-
assert_dynamic_through_type_is_val_info::<&'static str>();
370+
assert_type_info_is_primitive::<bool>(ReflectionPrimitiveKind::Bool);
371+
assert_type_info_is_primitive::<i8>(ReflectionPrimitiveKind::I8);
372+
assert_type_info_is_primitive::<i16>(ReflectionPrimitiveKind::I16);
373+
assert_type_info_is_primitive::<i32>(ReflectionPrimitiveKind::I32);
374+
assert_type_info_is_primitive::<i64>(ReflectionPrimitiveKind::I64);
375+
assert_type_info_is_primitive::<i128>(ReflectionPrimitiveKind::I128);
376+
assert_type_info_is_primitive::<u8>(ReflectionPrimitiveKind::U8);
377+
assert_type_info_is_primitive::<u16>(ReflectionPrimitiveKind::U16);
378+
assert_type_info_is_primitive::<u32>(ReflectionPrimitiveKind::U32);
379+
assert_type_info_is_primitive::<u64>(ReflectionPrimitiveKind::U64);
380+
assert_type_info_is_primitive::<u128>(ReflectionPrimitiveKind::U128);
381+
assert_type_info_is_primitive::<f32>(ReflectionPrimitiveKind::F32);
382+
assert_type_info_is_primitive::<f64>(ReflectionPrimitiveKind::F64);
383+
assert_type_info_is_primitive::<usize>(ReflectionPrimitiveKind::Usize);
384+
assert_type_info_is_primitive::<isize>(ReflectionPrimitiveKind::Isize);
385+
assert_type_info_is_primitive::<String>(ReflectionPrimitiveKind::String);
386+
assert_type_info_is_primitive::<PathBuf>(ReflectionPrimitiveKind::PathBuf);
387+
assert_type_info_is_primitive::<OsString>(ReflectionPrimitiveKind::OsString);
388+
assert_type_info_is_primitive::<char>(ReflectionPrimitiveKind::Char);
389+
assert_type_info_is_primitive::<ReflectReference>(
390+
ReflectionPrimitiveKind::ReflectReference,
391+
);
392+
assert_type_info_is_primitive::<&'static str>(ReflectionPrimitiveKind::Str);
419393
}
420394

421395
#[test]

crates/lad_backends/lua_language_server_lad_backend/tests/example_ladfile/expected.lua

Lines changed: 131 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,161 @@
11
---@meta
22
---@module "PlainStructType"
33

4-
---@class PlainStructType
4+
---@class PlainStructType : ReflectReference
55
--- I am a simple plain struct type
66
---@field int_field ? integer
77
PlainStructType = {}
88

9-
---@package
109
---@param p1 PlainStructType
11-
1210
---@param p2 integer
13-
1411
---@return any
1512
function PlainStructType:plain_struct_function(p1,p2) end
1613

1714

18-
---@class EnumType
15+
---@class Bool
16+
--- A boolean value
17+
Bool = {}
18+
19+
20+
---@class Char
21+
--- An 8-bit character
22+
Char = {}
23+
24+
25+
---@class DynamicFunction
26+
--- A callable dynamic function
27+
DynamicFunction = {}
28+
29+
30+
---@class DynamicFunctionMut
31+
--- A stateful and callable dynamic function
32+
DynamicFunctionMut = {}
33+
34+
35+
---@class F32
36+
--- A 32-bit floating point number
37+
F32 = {}
38+
39+
40+
---@class F64
41+
--- A 64-bit floating point number
42+
F64 = {}
43+
44+
45+
---@class FunctionCallContext
46+
--- Function call context, if accepted by a function, means the function can access the world in arbitrary ways.
47+
FunctionCallContext = {}
48+
49+
50+
---@class I128
51+
--- A signed 128-bit integer
52+
I128 = {}
53+
54+
55+
---@class I16
56+
--- A signed 16-bit integer
57+
I16 = {}
58+
59+
60+
---@class I32
61+
--- A signed 32-bit integer
62+
I32 = {}
63+
64+
65+
---@class I64
66+
--- A signed 64-bit integer
67+
I64 = {}
68+
69+
70+
---@class I8
71+
--- A signed 8-bit integer
72+
I8 = {}
73+
74+
75+
---@class Isize
76+
--- A signed pointer-sized integer
77+
Isize = {}
78+
79+
80+
---@class OsString
81+
--- A heap allocated OS string
82+
OsString = {}
83+
84+
85+
---@class PathBuf
86+
--- A heap allocated file path
87+
PathBuf = {}
88+
89+
90+
---@class ReflectReference
91+
--- A reference to a reflectable type
92+
ReflectReference = {}
93+
94+
95+
---@class ScriptValue
96+
--- A value representing the union of all representable values
97+
ScriptValue = {}
98+
99+
100+
---@class Str
101+
--- A string slice
102+
Str = {}
103+
104+
105+
---@class String
106+
--- A heap allocated string
107+
String = {}
108+
109+
110+
---@class U128
111+
--- An unsigned 128-bit integer
112+
U128 = {}
113+
114+
115+
---@class U16
116+
--- An unsigned 16-bit integer
117+
U16 = {}
118+
119+
120+
---@class U32
121+
--- An unsigned 32-bit integer
122+
U32 = {}
123+
124+
125+
---@class U64
126+
--- An unsigned 64-bit integer
127+
U64 = {}
128+
129+
130+
---@class U8
131+
--- An unsigned 8-bit integer
132+
U8 = {}
133+
134+
135+
---@class Usize
136+
--- An unsigned pointer-sized integer
137+
Usize = {}
138+
19139

140+
---@class EnumType : ReflectReference
20141
EnumType = {}
21142

22143

23-
---@class TupleStructType
144+
---@class TupleStructType : ReflectReference
24145
--- I am a tuple test type
25-
---@field [1] ? integer
26-
---@field [2] ? string
146+
---@field [1] integer
147+
---@field [2] string
27148
TupleStructType = {}
28149

29150

30-
---@class UnitType
151+
---@class UnitType : ReflectReference
31152
--- I am a unit test type
32153
UnitType = {}
33154

34155

35156

36157

37-
---@type GenericStructType
158+
---@type any
38159
--- A static class allowing calls through the "." operator only.
39160
my_static_instance = {}
40161

crates/lad_backends/lua_language_server_lad_backend/tests/integration_tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn main() {
8282
if std::env::var("BLESS_MODE").is_ok() {
8383
std::fs::write(&expected_path, &generated_str)
8484
.expect("failed to write expected.lua file");
85+
panic!("BLESS_MODE is enabled, please disable it to run the tests");
8586
} else {
8687
pretty_assertions::assert_eq!(
8788
expected_str,
@@ -92,7 +93,4 @@ fn main() {
9293
}
9394
}
9495
}
95-
if std::env::var("BLESS_MODE").is_ok() {
96-
panic!("BLESS_MODE is enabled, please disable it to run the tests");
97-
}
9896
}

0 commit comments

Comments
 (0)