1+ package runtime_test
2+
3+ import (
4+ "testing"
5+
6+ . "github.com/smartystreets/goconvey/convey"
7+
8+ "github.com/MontFerret/ferret/pkg/runtime"
9+ )
10+
11+ func TestAssertions (t * testing.T ) {
12+ Convey ("Assertion Functions" , t , func () {
13+
14+ Convey ("AssertString" , func () {
15+ Convey ("Should pass for String type" , func () {
16+ str := runtime .NewString ("test" )
17+ err := runtime .AssertString (str )
18+ So (err , ShouldBeNil )
19+ })
20+
21+ Convey ("Should fail for non-String types" , func () {
22+ err := runtime .AssertString (runtime .NewInt (42 ))
23+ So (err , ShouldNotBeNil )
24+
25+ err = runtime .AssertString (runtime .NewFloat (3.14 ))
26+ So (err , ShouldNotBeNil )
27+
28+ err = runtime .AssertString (runtime .True )
29+ So (err , ShouldNotBeNil )
30+ })
31+ })
32+
33+ Convey ("AssertInt" , func () {
34+ Convey ("Should pass for Int type" , func () {
35+ val := runtime .NewInt (42 )
36+ err := runtime .AssertInt (val )
37+ So (err , ShouldBeNil )
38+ })
39+
40+ Convey ("Should fail for non-Int types" , func () {
41+ err := runtime .AssertInt (runtime .NewString ("test" ))
42+ So (err , ShouldNotBeNil )
43+
44+ err = runtime .AssertInt (runtime .NewFloat (3.14 ))
45+ So (err , ShouldNotBeNil )
46+
47+ err = runtime .AssertInt (runtime .True )
48+ So (err , ShouldNotBeNil )
49+ })
50+ })
51+
52+ Convey ("AssertFloat" , func () {
53+ Convey ("Should pass for Float type" , func () {
54+ val := runtime .NewFloat (3.14 )
55+ err := runtime .AssertFloat (val )
56+ So (err , ShouldBeNil )
57+ })
58+
59+ Convey ("Should fail for non-Float types" , func () {
60+ err := runtime .AssertFloat (runtime .NewString ("test" ))
61+ So (err , ShouldNotBeNil )
62+
63+ err = runtime .AssertFloat (runtime .NewInt (42 ))
64+ So (err , ShouldNotBeNil )
65+
66+ err = runtime .AssertFloat (runtime .True )
67+ So (err , ShouldNotBeNil )
68+ })
69+ })
70+
71+ Convey ("AssertNumber" , func () {
72+ Convey ("Should pass for numeric types" , func () {
73+ err := runtime .AssertNumber (runtime .NewInt (42 ))
74+ So (err , ShouldBeNil )
75+
76+ err = runtime .AssertNumber (runtime .NewFloat (3.14 ))
77+ So (err , ShouldBeNil )
78+ })
79+
80+ Convey ("Should fail for non-numeric types" , func () {
81+ err := runtime .AssertNumber (runtime .NewString ("test" ))
82+ So (err , ShouldNotBeNil )
83+
84+ err = runtime .AssertNumber (runtime .True )
85+ So (err , ShouldNotBeNil )
86+
87+ err = runtime .AssertNumber (runtime .NewObject ())
88+ So (err , ShouldNotBeNil )
89+ })
90+ })
91+
92+ Convey ("AssertBoolean" , func () {
93+ Convey ("Should pass for Boolean type" , func () {
94+ err := runtime .AssertBoolean (runtime .True )
95+ So (err , ShouldBeNil )
96+
97+ err = runtime .AssertBoolean (runtime .False )
98+ So (err , ShouldBeNil )
99+ })
100+
101+ Convey ("Should fail for non-Boolean types" , func () {
102+ err := runtime .AssertBoolean (runtime .NewString ("test" ))
103+ So (err , ShouldNotBeNil )
104+
105+ err = runtime .AssertBoolean (runtime .NewInt (42 ))
106+ So (err , ShouldNotBeNil )
107+
108+ err = runtime .AssertBoolean (runtime .NewFloat (3.14 ))
109+ So (err , ShouldNotBeNil )
110+ })
111+ })
112+
113+ Convey ("AssertCollection" , func () {
114+ Convey ("Should pass for Collection types" , func () {
115+ arr := runtime .NewArray (5 )
116+ err := runtime .AssertCollection (arr )
117+ So (err , ShouldBeNil )
118+
119+ obj := runtime .NewObject ()
120+ err = runtime .AssertCollection (obj )
121+ So (err , ShouldBeNil )
122+ })
123+
124+ Convey ("Should fail for non-Collection types" , func () {
125+ err := runtime .AssertCollection (runtime .NewString ("test" ))
126+ So (err , ShouldNotBeNil )
127+
128+ err = runtime .AssertCollection (runtime .NewInt (42 ))
129+ So (err , ShouldNotBeNil )
130+
131+ err = runtime .AssertCollection (runtime .True )
132+ So (err , ShouldNotBeNil )
133+ })
134+ })
135+
136+ Convey ("AssertArray" , func () {
137+ Convey ("Should pass for Array type" , func () {
138+ arr := runtime .NewArray (5 )
139+ err := runtime .AssertArray (arr )
140+ So (err , ShouldBeNil )
141+ })
142+
143+ Convey ("Should fail for non-Array types" , func () {
144+ err := runtime .AssertArray (runtime .NewObject ())
145+ So (err , ShouldNotBeNil )
146+
147+ err = runtime .AssertArray (runtime .NewString ("test" ))
148+ So (err , ShouldNotBeNil )
149+
150+ err = runtime .AssertArray (runtime .NewInt (42 ))
151+ So (err , ShouldNotBeNil )
152+ })
153+ })
154+
155+ Convey ("AssertList" , func () {
156+ Convey ("Should pass for List type" , func () {
157+ arr := runtime .NewArray (5 )
158+ err := runtime .AssertList (arr )
159+ So (err , ShouldBeNil )
160+ })
161+
162+ Convey ("Should fail for non-List types" , func () {
163+ err := runtime .AssertList (runtime .NewObject ())
164+ So (err , ShouldNotBeNil )
165+
166+ err = runtime .AssertList (runtime .NewString ("test" ))
167+ So (err , ShouldNotBeNil )
168+
169+ err = runtime .AssertList (runtime .NewInt (42 ))
170+ So (err , ShouldNotBeNil )
171+ })
172+ })
173+
174+ Convey ("AssertObject" , func () {
175+ Convey ("Should pass for Object type" , func () {
176+ obj := runtime .NewObject ()
177+ err := runtime .AssertObject (obj )
178+ So (err , ShouldBeNil )
179+ })
180+
181+ Convey ("Should fail for non-Object types" , func () {
182+ err := runtime .AssertObject (runtime .NewArray (5 ))
183+ So (err , ShouldNotBeNil )
184+
185+ err = runtime .AssertObject (runtime .NewString ("test" ))
186+ So (err , ShouldNotBeNil )
187+
188+ err = runtime .AssertObject (runtime .NewInt (42 ))
189+ So (err , ShouldNotBeNil )
190+ })
191+ })
192+
193+ Convey ("AssertMap" , func () {
194+ Convey ("Should pass for Map type" , func () {
195+ obj := runtime .NewObject ()
196+ err := runtime .AssertMap (obj )
197+ So (err , ShouldBeNil )
198+ })
199+
200+ Convey ("Should fail for non-Map types" , func () {
201+ err := runtime .AssertMap (runtime .NewArray (5 ))
202+ So (err , ShouldNotBeNil )
203+
204+ err = runtime .AssertMap (runtime .NewString ("test" ))
205+ So (err , ShouldNotBeNil )
206+
207+ err = runtime .AssertMap (runtime .NewInt (42 ))
208+ So (err , ShouldNotBeNil )
209+ })
210+ })
211+
212+ Convey ("AssertBinary" , func () {
213+ Convey ("Should pass for Binary type" , func () {
214+ bin := runtime .NewBinary ([]byte ("test" ))
215+ err := runtime .AssertBinary (bin )
216+ So (err , ShouldBeNil )
217+ })
218+
219+ Convey ("Should fail for non-Binary types" , func () {
220+ err := runtime .AssertBinary (runtime .NewString ("test" ))
221+ So (err , ShouldNotBeNil )
222+
223+ err = runtime .AssertBinary (runtime .NewInt (42 ))
224+ So (err , ShouldNotBeNil )
225+
226+ err = runtime .AssertBinary (runtime .NewObject ())
227+ So (err , ShouldNotBeNil )
228+ })
229+ })
230+
231+ Convey ("AssertDateTime" , func () {
232+ Convey ("Should pass for DateTime type" , func () {
233+ dt := runtime .NewCurrentDateTime ()
234+ err := runtime .AssertDateTime (dt )
235+ So (err , ShouldBeNil )
236+ })
237+
238+ Convey ("Should fail for non-DateTime types" , func () {
239+ err := runtime .AssertDateTime (runtime .NewString ("test" ))
240+ So (err , ShouldNotBeNil )
241+
242+ err = runtime .AssertDateTime (runtime .NewInt (42 ))
243+ So (err , ShouldNotBeNil )
244+
245+ err = runtime .AssertDateTime (runtime .NewObject ())
246+ So (err , ShouldNotBeNil )
247+ })
248+ })
249+
250+ Convey ("AssertMeasurable" , func () {
251+ Convey ("Should pass for Measurable types" , func () {
252+ // Array is Measurable
253+ arr := runtime .NewArray (5 )
254+ err := runtime .AssertMeasurable (arr )
255+ So (err , ShouldBeNil )
256+
257+ // String is Measurable
258+ str := runtime .NewString ("test" )
259+ err = runtime .AssertMeasurable (str )
260+ So (err , ShouldBeNil )
261+
262+ // Binary is Measurable
263+ bin := runtime .NewBinary ([]byte ("test" ))
264+ err = runtime .AssertMeasurable (bin )
265+ So (err , ShouldBeNil )
266+ })
267+
268+ Convey ("Should fail for non-Measurable types" , func () {
269+ err := runtime .AssertMeasurable (runtime .NewInt (42 ))
270+ So (err , ShouldNotBeNil )
271+
272+ err = runtime .AssertMeasurable (runtime .NewFloat (3.14 ))
273+ So (err , ShouldNotBeNil )
274+
275+ err = runtime .AssertMeasurable (runtime .True )
276+ So (err , ShouldNotBeNil )
277+ })
278+ })
279+ })
280+ }
0 commit comments