Skip to content

Commit e172533

Browse files
committed
test: add tests for reworked InteractionInput class
1 parent ef81993 commit e172533

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright 2023 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import 'package:dart_wot/scripting_api.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
group('InteractionInput', () {
12+
group('should be able to be instantiated from', () {
13+
test('null', () {
14+
final interactionInput = InteractionInput.fromNull();
15+
16+
expect(interactionInput, isA<DataSchemaValueInput>());
17+
18+
expect(
19+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
20+
isA<NullValue>(),
21+
);
22+
23+
final alternativeInteractionInput = null.asInteractionInput();
24+
expect(interactionInput, alternativeInteractionInput);
25+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
26+
});
27+
28+
test('a String', () {
29+
const testValue = 'foo';
30+
final interactionInput = InteractionInput.fromString(testValue);
31+
32+
expect(interactionInput, isA<DataSchemaValueInput>());
33+
34+
expect(
35+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
36+
isA<StringValue>(),
37+
);
38+
39+
expect(
40+
interactionInput.dataSchemaValue,
41+
DataSchemaValue.fromString(testValue),
42+
);
43+
44+
final alternativeInteractionInput = testValue.asInteractionInput();
45+
expect(interactionInput, alternativeInteractionInput);
46+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
47+
});
48+
49+
test('an Integer', () {
50+
const testValue = 42;
51+
final interactionInput = InteractionInput.fromInteger(testValue);
52+
53+
expect(interactionInput, isA<DataSchemaValueInput>());
54+
55+
expect(
56+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
57+
isA<IntegerValue>(),
58+
);
59+
60+
expect(
61+
interactionInput.dataSchemaValue,
62+
DataSchemaValue.fromInteger(testValue),
63+
);
64+
65+
final alternativeInteractionInput = testValue.asInteractionInput();
66+
expect(interactionInput, alternativeInteractionInput);
67+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
68+
});
69+
70+
test('a Number', () {
71+
const testValue = 42.0;
72+
final interactionInput = InteractionInput.fromNumber(testValue);
73+
74+
expect(interactionInput, isA<DataSchemaValueInput>());
75+
76+
expect(
77+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
78+
isA<NumberValue>(),
79+
);
80+
81+
expect(
82+
interactionInput.dataSchemaValue,
83+
DataSchemaValue.fromNumber(testValue),
84+
);
85+
86+
final alternativeInteractionInput = testValue.asInteractionInput();
87+
expect(interactionInput, alternativeInteractionInput);
88+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
89+
});
90+
91+
test('a Boolean', () {
92+
const testValue = true;
93+
final interactionInput = InteractionInput.fromBoolean(testValue);
94+
95+
expect(interactionInput, isA<DataSchemaValueInput>());
96+
97+
expect(
98+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
99+
isA<BooleanValue>(),
100+
);
101+
102+
expect(
103+
interactionInput.dataSchemaValue,
104+
DataSchemaValue.fromBoolean(testValue),
105+
);
106+
107+
final alternativeInteractionInput = testValue.asInteractionInput();
108+
expect(interactionInput, alternativeInteractionInput);
109+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
110+
});
111+
112+
test('an Array', () {
113+
const testValue = [true, 42, 'foo'];
114+
final interactionInput = InteractionInput.fromArray(testValue);
115+
116+
expect(interactionInput, isA<DataSchemaValueInput>());
117+
118+
expect(
119+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
120+
isA<ArrayValue>(),
121+
);
122+
123+
expect(
124+
interactionInput.dataSchemaValue,
125+
DataSchemaValue.fromArray(testValue),
126+
);
127+
128+
expect(
129+
interactionInput.dataSchemaValue.hashCode,
130+
DataSchemaValue.fromArray(testValue).hashCode,
131+
);
132+
133+
final alternativeInteractionInput = testValue.asInteractionInput();
134+
expect(interactionInput, alternativeInteractionInput);
135+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
136+
});
137+
138+
test('an Object', () {
139+
const testValue = <String, Object?>{
140+
'bool': true,
141+
'int': 42,
142+
'string': 'foo',
143+
'number': 42.0,
144+
'null': null,
145+
'array': [true, 'bar', 42],
146+
'object': {
147+
'string': 'baz',
148+
},
149+
};
150+
final interactionInput = InteractionInput.fromObject(testValue);
151+
152+
expect(interactionInput, isA<DataSchemaValueInput>());
153+
154+
expect(
155+
(interactionInput as DataSchemaValueInput).dataSchemaValue,
156+
isA<ObjectValue>(),
157+
);
158+
159+
expect(
160+
interactionInput.dataSchemaValue,
161+
DataSchemaValue.fromObject(testValue),
162+
);
163+
164+
expect(
165+
interactionInput.dataSchemaValue.hashCode,
166+
DataSchemaValue.fromObject(testValue).hashCode,
167+
);
168+
169+
final alternativeInteractionInput = testValue.asInteractionInput();
170+
expect(interactionInput, alternativeInteractionInput);
171+
expect(interactionInput.hashCode, alternativeInteractionInput.hashCode);
172+
});
173+
174+
test('a byte stream', () {
175+
final testValue = Stream.fromIterable([
176+
[0, 1, 2],
177+
[3, 4, 5],
178+
]);
179+
final interactionInput = InteractionInput.fromStream(testValue);
180+
181+
expect(interactionInput, isA<StreamInput>());
182+
});
183+
});
184+
});
185+
}

0 commit comments

Comments
 (0)