1+ import pytest
2+
3+ from chaotic .back .cpp import translator as cpp_translator
14from chaotic .back .cpp import type_name
25from chaotic .back .cpp import types as cpp_types
36from chaotic .front import types as front_types
@@ -21,6 +24,71 @@ def test_array_int(simple_gen, cpp_primitive_type):
2124 }
2225
2326
27+ @pytest .mark .parametrize (
28+ 'item_schema,expected_cpp_type,expected_validators' ,
29+ [
30+ (
31+ {'type' : 'integer' },
32+ 'int' ,
33+ cpp_types .CppPrimitiveValidator (prefix = 'typeA' ),
34+ ),
35+ (
36+ {'type' : 'string' },
37+ 'std::string' ,
38+ cpp_types .CppPrimitiveValidator (prefix = 'typeA' ),
39+ ),
40+ (
41+ {'type' : 'boolean' },
42+ 'bool' ,
43+ cpp_types .CppPrimitiveValidator (),
44+ ),
45+ ],
46+ )
47+ def test_array_unique_items_valid_types (
48+ simple_gen ,
49+ cpp_primitive_type ,
50+ item_schema ,
51+ expected_cpp_type ,
52+ expected_validators ,
53+ ):
54+ types = simple_gen ({
55+ 'type' : 'array' ,
56+ 'uniqueItems' : True ,
57+ 'items' : item_schema ,
58+ })
59+ assert types == {
60+ '::type' : cpp_types .CppArray (
61+ raw_cpp_type = type_name .TypeName ('::type' ),
62+ user_cpp_type = None ,
63+ json_schema = front_types .Schema (),
64+ nullable = False ,
65+ items = cpp_primitive_type (
66+ validators = expected_validators ,
67+ raw_cpp_type_str = expected_cpp_type ,
68+ ),
69+ container = 'std::vector' ,
70+ validators = cpp_types .CppArrayValidator (uniqueItems = True ),
71+ ),
72+ }
73+
74+
75+ @pytest .mark .parametrize (
76+ 'item_schema' ,
77+ [
78+ {'type' : 'number' },
79+ {'type' : 'array' , 'items' : {'type' : 'integer' }},
80+ ],
81+ )
82+ def test_array_unique_items_invalid_type (simple_gen , item_schema ):
83+ with pytest .raises (cpp_translator .TranslatorError ) as exc :
84+ simple_gen ({
85+ 'type' : 'array' ,
86+ 'uniqueItems' : True ,
87+ 'items' : item_schema ,
88+ })
89+ assert exc .value .msg == ('uniqueItems is only supported for integer, string, and boolean item types' )
90+
91+
2492def test_array_array_with_validators (simple_gen , cpp_primitive_type ):
2593 types = simple_gen ({
2694 'type' : 'array' ,
0 commit comments