-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_test.go
1088 lines (942 loc) · 56.7 KB
/
template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package templateStr
import (
"fmt"
"reflect"
"testing"
ti "time"
tem "github.com/CheeseGrinder/TemplateStr-Go/templateStr"
)
var Reset = "\033[0m"
var Red = "\033[31m"
var Green = "\033[32m"
var Yellow = "\033[33m"
type Any = interface{}
type VarMap = tem.VariableMap
type FuncArray = tem.FuncArray
func test(_ []Any) string {
return "Test1"
}
func testType(array []Any) string {
var result string
TypeOf := func(t Any) reflect.Kind {
return reflect.TypeOf(t).Kind()
}
a := array[0]
b := array[1]
c := array[2]
d := array[3]
e := array[4]
f := array[5]
g := array[6]
h := array[7]
i := array[8]
j := array[9]
// test a
if TypeOf(a) != reflect.String {
result += "| type a != string"
} else {
if a != "text" {
result += `| a != "text"`
}
}
// test b
if TypeOf(b) != reflect.String {
result += "| type b != string"
} else {
if b != "text" {
result += `| b != "text"`
}
}
// test c
if TypeOf(c) != reflect.String {
result += "| type c != string"
} else {
if c != "text" {
result += `| c != "text"`
}
}
// test d
if TypeOf(d) != reflect.Bool {
result += "| type d != bool"
} else {
if d != true {
result += `| d != true`
}
}
// test e
if TypeOf(e) != reflect.Int {
result += "| type e != int"
} else {
if e != 123 {
result += `| e != 123`
}
}
// test f
if TypeOf(f) != reflect.Float64 {
result += "| type f != float64"
} else {
if f != 123.4 {
result += `| f != 123.4`
}
}
// test g
if TypeOf(g) != reflect.Int {
result += "| type g != int"
} else {
if g != 32 {
result += `| g != 32`
}
}
// test h
if TypeOf(h) != reflect.Int {
result += "| type h != int"
} else {
if h != 42 {
result += `| h != 42`
}
}
// test i
if TypeOf(i) != reflect.Slice {
result += "| i != slice"
} else {
if i := i.([]Any); i[1] != 56 {
result += `| i != 56`
}
}
// test j
if TypeOf(j) != reflect.String {
result += "| type j != string"
} else {
if j != "Map in Map" {
result += `| j != "Map in Map"`
}
}
if result == "" {
return "ok"
}
return result
}
var arrayFunc FuncArray = FuncArray{testType, test}
var varMap VarMap = VarMap{
"Build": "Succes",
"var": "int",
"str": "Jame",
"int": 32,
"float": 4.2,
"bool": true,
"lower": "azerty",
"upper": "AZERTY",
"swap": "AzErTy",
"array": []Any{"test", 42},
// "cfold": "grüßen",
"Map": VarMap{
"value": "Map in Map",
},
"MasterMap": VarMap{
"SecondMap": VarMap{
"value": "Map in Map in Map",
},
},
}
func TestAll(t *testing.T) {
testAll_1 := []string{
"Name is @{uppercase; str}, ${int} years old. Map: ${Map.value}. my keyboard: #{lower == 'azerty'; azerty | qwerty}, ?{lower; azerty::yes, AZERTY::no, _::anyway}",
"Name is JAME, 32 years old. Map: Map in Map. my keyboard: azerty, yes",
}
testAll_2 := []string{"test var in var ${${var}}", "test var in var 32"}
testAll_3 := []string{"test if in if #{lower == 'azerty2'; azerty | #{lower == 'querty'; yes | no}}", "test if in if no"}
testAll_4 := []string{"test switch in switch ?{str; Jame::?{Build; Succes::#0, Failed::#1, _::#default}, Tony::#1, Marco::#2, _::#default}", "test switch in switch #0"}
testAll_5 := []string{"test wtf ?{str; Jame::?{int/${var}; 32::#0, 36::#1, _::#default}, Tony::#1, Marco::#2, _::#default2}", "test wtf #0"}
// Error case
testAll_error_1 := []string{"test func in func @{lowercase; @{uppercase; str}}", "NotFoundVariableError: [key '[JAME]' not exist]"}
parser := tem.New(arrayFunc, varMap)
if text, _ := parser.Parse(testAll_1[0]); text != testAll_1[1] {
t.Fatalf("testAll_1 : '" + Red + text + Reset + "' != '" + Yellow + testAll_1[1] + Reset + "'")
}
if text, _ := parser.Parse(testAll_2[0]); text != testAll_2[1] {
t.Fatalf("testAll_2 : '" + Red + text + Reset + "' != '" + Yellow + testAll_2[1] + Reset + "'")
}
if text, _ := parser.Parse(testAll_3[0]); text != testAll_3[1] {
t.Fatalf("testAll_3 : '" + Red + text + Reset + "' != '" + Yellow + testAll_3[1] + Reset + "'")
}
if text, _ := parser.Parse(testAll_4[0]); text != testAll_4[1] {
t.Fatalf("testAll_4 : '" + Red + text + Reset + "' != '" + Yellow + testAll_4[1] + Reset + "'")
}
if text, _ := parser.Parse(testAll_5[0]); text != testAll_5[1] {
t.Fatalf("testAll_5 : '" + Red + text + Reset + "' != '" + Yellow + testAll_5[1] + Reset + "'")
}
// Error case
print("error")
if _, err := parser.Parse(testAll_error_1[0]); fmt.Sprint(err) != testAll_error_1[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + testAll_error_1[1] + Reset + "'")
}
}
func TestVariable(t *testing.T) {
text_1 := []string{"var bool = ${bool} and name = ${str}", "var bool = true and name = Jame"}
text_2 := []string{"${Map.value}", "Map in Map"}
text_3 := []string{"${MasterMap.SecondMap.value}", "Map in Map in Map"}
text_4 := []string{"${array[0]}", "test"}
// Error case
text_error_1 := []string{"${word}", "NotFoundVariableError: [key '[word]' not exist]"}
text_error_2 := []string{"${dict.dict1.value}", "NotFoundVariableError: [key '[dict.dict1.value]' not exist]"}
text_error_3 := []string{"${Build[0]}", "NotAArrayError: [key '[Build]' is not array]"}
text_error_4 := []string{"${array[2]}", "IndexError: [index '[2]' out of range]"}
parser := tem.New(FuncArray{}, varMap)
if text, _ := parser.ParseVariable(text_1[0]); text != text_1[1] {
t.Fatalf("text_1 : '" + Red + text + Reset + "' != '" + Yellow + text_1[1] + Reset + "'")
}
if text, _ := parser.ParseVariable(text_2[0]); text != text_2[1] {
t.Fatalf("text_2 : '" + Red + text + Reset + "' != '" + Yellow + text_2[1] + Reset + "'")
}
if text, _ := parser.ParseVariable(text_3[0]); text != text_3[1] {
t.Fatalf("text_3 : '" + Red + text + Reset + "' != '" + Yellow + text_3[1] + Reset + "'")
}
if text, _ := parser.ParseVariable(text_4[0]); text != text_4[1] {
t.Fatalf("text_4 : '" + Red + text + Reset + "' != '" + Yellow + text_4[1] + Reset + "'")
}
// Error case
if _, err := parser.Parse(text_error_1[0]); fmt.Sprint(err) != text_error_1[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + text_error_1[1] + Reset + "'")
}
if _, err := parser.Parse(text_error_2[0]); fmt.Sprint(err) != text_error_2[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + text_error_2[1] + Reset + "'")
}
if _, err := parser.Parse(text_error_3[0]); fmt.Sprint(err) != text_error_3[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + text_error_3[1] + Reset + "'")
}
if _, err := parser.Parse(text_error_4[0]); fmt.Sprint(err) != text_error_4[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + text_error_4[1] + Reset + "'")
}
}
func TestInternFunction(t *testing.T) {
uppercase := []string{"@{uppercase; lower}", "AZERTY"}
uppercaseFirst := []string{"@{uppercaseFirst; lower}", "Azerty"}
lowercase := []string{"@{lowercase; upper}", "azerty"}
// casefold := []string{"@{casefold cfold}", "grüssen"}
swapcase := []string{"@{swapcase; swap}", "aZeRtY"}
time := "@{time}"
date := "@{date}"
dateTime := "@{dateTime}"
// Error case
uppercase_error := []string{"@{uppercase; test}", "NotFoundVariableError: [key '[test]' not exist]"}
parser := tem.New(FuncArray{}, varMap)
if text, _ := parser.ParseFunction(uppercase[0]); text != uppercase[1] {
t.Fatalf("uppercase : '" + Red + text + Reset + "' != '" + Yellow + uppercase[1] + Reset + "'")
}
if text, _ := parser.ParseFunction(uppercaseFirst[0]); text != uppercaseFirst[1] {
t.Fatalf("uppercaseFirst : '" + Red + text + Reset + "' != '" + Yellow + uppercaseFirst[1] + Reset + "'")
}
if text, _ := parser.ParseFunction(lowercase[0]); text != lowercase[1] {
t.Fatalf("lowercase : '" + Red + text + Reset + "' != '" + Yellow + lowercase[1] + Reset + "'")
}
// if text, _ := parser.ParseFunction(casefold[0]); text != casefold[1] {t.Fatalf("casefold : '" + Red + text + Reset + "' != '" + Yellow + casefold[1] + Reset + "'")}
if text, _ := parser.ParseFunction(swapcase[0]); text != swapcase[1] {
t.Fatalf("swapcase : '" + Red + text + Reset + "' != '" + Yellow + swapcase[1] + Reset + "'")
}
dateTime1 := ti.Now()
if text, _ := parser.ParseFunction(time); text != dateTime1.Format("15:04:05") {
t.Fatalf("time : '" + Red + text + Reset + "' != '" + Yellow + dateTime1.Format("15:04:05") + Reset + "'")
}
if text, _ := parser.ParseFunction(date); text != dateTime1.Format("02/01/2006") {
t.Fatalf("date : '" + Red + text + Reset + "' != '" + Yellow + dateTime1.Format("02/01/2006") + Reset + "'")
}
dateTime2 := ti.Now()
if text, _ := parser.ParseFunction(dateTime); text != dateTime2.Format("02/01/2006 15:04:05") {
t.Fatalf("dateTime : '" + Red + text + Reset + "' != '" + Yellow + dateTime2.Format("02/01/2006 15:04:05") + Reset + "'")
}
// Error case
if _, err := parser.Parse(uppercase_error[0]); fmt.Sprint(err) != uppercase_error[1] {
t.Fatalf("testAll_panic_1 : '" + Red + fmt.Sprint(err) + Reset + "' != '" + Yellow + uppercase_error[1] + Reset + "'")
}
}
func TestCustomFunction(t *testing.T) {
test := []string{"@{test}", "Test1"}
testType := []string{"@{testType; \"text\" 'text' `text` b/True i/123 f/123.4 int array[1] ('test', i/56) Map.value}", "ok"}
parser := tem.New(arrayFunc, varMap)
if text, _ := parser.ParseFunction(test[0]); text != test[1] {
t.Fatalf("'" + Red + text + Reset + "' != '" + Yellow + test[1] + Reset + "'")
}
if text, _ := parser.ParseFunction(testType[0]); text != testType[1] {
t.Fatalf("'" + Red + text + Reset + "' != '" + Yellow + testType[1] + Reset + "'")
}
}
func TestConditionEqual(t *testing.T) {
str_Equal_Str := []string{"#{'text' == 'text'; yes | no}", "yes"}
str_Equal2_Str := []string{"#{'text' == 'texte'; yes | no}", "no"}
int_Equal_Str := []string{"#{i/4 == 'text'; yes | no}", "no"}
float_Equal_Str := []string{"#{f/4.5 == 'texte'; yes | no}", "no"}
bool_Equal_Str := []string{"#{b/True == 'texte'; yes | no}", "no"}
parser := tem.New(FuncArray{}, varMap)
if text, _ := parser.ParseCondition(str_Equal_Str[0]); text != str_Equal_Str[1] {
t.Fatalf("str_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Equal2_Str[0]); text != str_Equal2_Str[1] {
t.Fatalf("str_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Equal_Str[0]); text != int_Equal_Str[1] {
t.Fatalf("int_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Equal_Str[0]); text != float_Equal_Str[1] {
t.Fatalf("float_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Equal_Str[0]); text != bool_Equal_Str[1] {
t.Fatalf("bool_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Equal_Str[1] + Reset + "'")
}
}
func TestConditionNotEqual(t *testing.T) {
str_Not_Equal_Str := []string{"#{'text' != 'text'; yes | no}", "no"}
str_Not_Equal2_Str := []string{"#{'text' != 'texte'; yes | no}", "yes"}
int_Not_Equal_Str := []string{"#{i/4 != 'text'; yes | no}", "yes"}
float_Not_Equal_Str := []string{"#{f/4.5 != 'texte'; yes | no}", "yes"}
bool_Not_Equal_Str := []string{"#{b/True != 'texte'; yes | no}", "yes"}
parser := tem.New(FuncArray{}, varMap)
if text, _ := parser.ParseCondition(str_Not_Equal_Str[0]); text != str_Not_Equal_Str[1] {
t.Fatalf("str_Not_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Not_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Not_Equal2_Str[0]); text != str_Not_Equal2_Str[1] {
t.Fatalf("str_Not_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Not_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Not_Equal_Str[0]); text != int_Not_Equal_Str[1] {
t.Fatalf("int_Not_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Not_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Not_Equal_Str[0]); text != float_Not_Equal_Str[1] {
t.Fatalf("float_Not_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Not_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Not_Equal_Str[0]); text != bool_Not_Equal_Str[1] {
t.Fatalf("bool_Not_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Not_Equal_Str[1] + Reset + "'")
}
}
func TestConditionSuperiorEqual(t *testing.T) {
parser := tem.New(FuncArray{}, varMap)
// String
str_Superior_Equal_Str := []string{"#{'text' >= 'text'; yes | no}", "yes"}
str_Superior_Equal2_Str := []string{"#{'text' >= 'texte'; yes | no}", "no"}
str_Superior_Equal_Int := []string{"#{'text' >= i/4; yes | no}", "yes"}
str_Superior_Equal2_Int := []string{"#{'text' >= i/123; yes | no}", "no"}
str_Superior_Equal_Float := []string{"#{'text' >= f/4.5; yes | no}", "no"}
str_Superior_Equal2_Float := []string{"#{'text' >= f/3.5; yes | no}", "yes"}
str_Superior_Equal_Bool := []string{"#{'text' >= b/True; yes | no}", "yes"}
str_Superior_Equal2_Bool := []string{"#{'text' >= b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(str_Superior_Equal_Str[0]); text != str_Superior_Equal_Str[1] {
t.Fatalf("str_Superior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal2_Str[0]); text != str_Superior_Equal2_Str[1] {
t.Fatalf("str_Superior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal_Int[0]); text != str_Superior_Equal_Int[1] {
t.Fatalf("str_Superior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal2_Int[0]); text != str_Superior_Equal2_Int[1] {
t.Fatalf("str_Superior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal_Float[0]); text != str_Superior_Equal_Float[1] {
t.Fatalf("str_Superior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal2_Float[0]); text != str_Superior_Equal2_Float[1] {
t.Fatalf("str_Superior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal_Bool[0]); text != str_Superior_Equal_Bool[1] {
t.Fatalf("str_Superior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Equal2_Bool[0]); text != str_Superior_Equal2_Bool[1] {
t.Fatalf("str_Superior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Equal2_Bool[1] + Reset + "'")
}
// Int
int_Superior_Equal_Str := []string{"#{i/4 >= 'text'; yes | no}", "yes"}
int_Superior_Equal2_Str := []string{"#{i/4 >= 'texte'; yes | no}", "no"}
int_Superior_Equal_Int := []string{"#{i/4 >= i/4; yes | no}", "yes"}
int_Superior_Equal2_Int := []string{"#{i/4 >= i/5; yes | no}", "no"}
int_Superior_Equal_Float := []string{"#{i/4 >= f/3.5; yes | no}", "yes"}
int_Superior_Equal2_Float := []string{"#{i/4 >= f/4.5; yes | no}", "no"}
int_Superior_Equal_Bool := []string{"#{i/4 >= b/True; yes | no}", "yes"}
int_Superior_Equal2_Bool := []string{"#{i/4 >= b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(int_Superior_Equal_Str[0]); text != int_Superior_Equal_Str[1] {
t.Fatalf("int_Superior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal2_Str[0]); text != int_Superior_Equal2_Str[1] {
t.Fatalf("int_Superior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal_Int[0]); text != int_Superior_Equal_Int[1] {
t.Fatalf("int_Superior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal2_Int[0]); text != int_Superior_Equal2_Int[1] {
t.Fatalf("int_Superior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal_Float[0]); text != int_Superior_Equal_Float[1] {
t.Fatalf("int_Superior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal2_Float[0]); text != int_Superior_Equal2_Float[1] {
t.Fatalf("int_Superior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal_Bool[0]); text != int_Superior_Equal_Bool[1] {
t.Fatalf("int_Superior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Equal2_Bool[0]); text != int_Superior_Equal2_Bool[1] {
t.Fatalf("int_Superior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Equal2_Bool[1] + Reset + "'")
}
// Float
float_Superior_Equal_Str := []string{"#{f/4.5 >= 'text'; yes | no}", "yes"}
float_Superior_Equal2_Str := []string{"#{f/4.5 >= 'texte'; yes | no}", "no"}
float_Superior_Equal_Int := []string{"#{f/4.5 >= i/4; yes | no}", "yes"}
float_Superior_Equal2_Int := []string{"#{f/4.5 >= i/5; yes | no}", "no"}
float_Superior_Equal_Float := []string{"#{f/4.5 >= f/4.5; yes | no}", "yes"}
float_Superior_Equal2_Float := []string{"#{f/4.5 >= f/4.6; yes | no}", "no"}
float_Superior_Equal_Bool := []string{"#{f/4.5 >= b/True; yes | no}", "yes"}
float_Superior_Equal2_Bool := []string{"#{f/4.5 >= b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(float_Superior_Equal_Str[0]); text != float_Superior_Equal_Str[1] {
t.Fatalf("float_Superior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal2_Str[0]); text != float_Superior_Equal2_Str[1] {
t.Fatalf("float_Superior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal_Int[0]); text != float_Superior_Equal_Int[1] {
t.Fatalf("float_Superior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal2_Int[0]); text != float_Superior_Equal2_Int[1] {
t.Fatalf("float_Superior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal_Float[0]); text != float_Superior_Equal_Float[1] {
t.Fatalf("float_Superior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal2_Float[0]); text != float_Superior_Equal2_Float[1] {
t.Fatalf("float_Superior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal_Bool[0]); text != float_Superior_Equal_Bool[1] {
t.Fatalf("float_Superior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Equal2_Bool[0]); text != float_Superior_Equal2_Bool[1] {
t.Fatalf("float_Superior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Equal2_Bool[1] + Reset + "'")
}
// Bool
bool_Superior_Equal_Str := []string{"#{b/True >= 'text'; yes | no}", "no"}
bool_Superior_Equal2_Str := []string{"#{b/False >= 'texte'; yes | no}", "no"}
bool_Superior_Equal_Int := []string{"#{b/True >= i/4; yes | no}", "no"}
bool_Superior_Equal2_Int := []string{"#{b/False >= i/5; yes | no}", "no"}
bool_Superior_Equal_Float := []string{"#{b/True >= f/4.5; yes | no}", "no"}
bool_Superior_Equal2_Float := []string{"#{b/False >= f/4.6; yes | no}", "no"}
bool_Superior_Equal_Bool := []string{"#{b/True >= b/True; yes | no}", "yes"}
bool_Superior_Equal2_Bool := []string{"#{b/False >= b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(bool_Superior_Equal_Str[0]); text != bool_Superior_Equal_Str[1] {
t.Fatalf("bool_Superior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal2_Str[0]); text != bool_Superior_Equal2_Str[1] {
t.Fatalf("bool_Superior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal_Int[0]); text != bool_Superior_Equal_Int[1] {
t.Fatalf("bool_Superior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal2_Int[0]); text != bool_Superior_Equal2_Int[1] {
t.Fatalf("bool_Superior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal_Float[0]); text != bool_Superior_Equal_Float[1] {
t.Fatalf("bool_Superior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal2_Float[0]); text != bool_Superior_Equal2_Float[1] {
t.Fatalf("bool_Superior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal_Bool[0]); text != bool_Superior_Equal_Bool[1] {
t.Fatalf("bool_Superior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Equal2_Bool[0]); text != bool_Superior_Equal2_Bool[1] {
t.Fatalf("bool_Superior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Equal2_Bool[1] + Reset + "'")
}
}
func TestConditionSuperior(t *testing.T) {
parser := tem.New(FuncArray{}, varMap)
// String
str_Superior_Str := []string{"#{'text' > 'text'; yes | no}", "no"}
str_Superior2_Str := []string{"#{'text' > 'texte'; yes | no}", "no"}
str_Superior_Int := []string{"#{'text' > i/4; yes | no}", "no"}
str_Superior2_Int := []string{"#{'text' > i/123; yes | no}", "no"}
str_Superior_Float := []string{"#{'text' > f/4.5; yes | no}", "no"}
str_Superior2_Float := []string{"#{'text' > f/3.5; yes | no}", "yes"}
str_Superior_Bool := []string{"#{'text' > b/True; yes | no}", "yes"}
str_Superior2_Bool := []string{"#{'text' > b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(str_Superior_Str[0]); text != str_Superior_Str[1] {
t.Fatalf("str_Superior_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior2_Str[0]); text != str_Superior2_Str[1] {
t.Fatalf("str_Superior2_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Superior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Int[0]); text != str_Superior_Int[1] {
t.Fatalf("str_Superior_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior2_Int[0]); text != str_Superior2_Int[1] {
t.Fatalf("str_Superior2_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Superior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Float[0]); text != str_Superior_Float[1] {
t.Fatalf("str_Superior_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior2_Float[0]); text != str_Superior2_Float[1] {
t.Fatalf("str_Superior2_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Superior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior_Bool[0]); text != str_Superior_Bool[1] {
t.Fatalf("str_Superior_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Superior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Superior2_Bool[0]); text != str_Superior2_Bool[1] {
t.Fatalf("str_Superior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Superior2_Bool[1] + Reset + "'")
}
// Int
int_Superior_Str := []string{"#{i/4 > 'text'; yes | no}", "no"}
int_Superior2_Str := []string{"#{i/4 > 'texte'; yes | no}", "no"}
int_Superior_Int := []string{"#{i/4 > i/4; yes | no}", "no"}
int_Superior2_Int := []string{"#{i/4 > i/5; yes | no}", "no"}
int_Superior_Float := []string{"#{i/4 > f/3.5; yes | no}", "yes"}
int_Superior2_Float := []string{"#{i/4 > f/4.5; yes | no}", "no"}
int_Superior_Bool := []string{"#{i/4 > b/True; yes | no}", "yes"}
int_Superior2_Bool := []string{"#{i/4 > b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(int_Superior_Str[0]); text != int_Superior_Str[1] {
t.Fatalf("int_Superior_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior2_Str[0]); text != int_Superior2_Str[1] {
t.Fatalf("int_Superior2_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Superior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Int[0]); text != int_Superior_Int[1] {
t.Fatalf("int_Superior_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior2_Int[0]); text != int_Superior2_Int[1] {
t.Fatalf("int_Superior2_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Superior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Float[0]); text != int_Superior_Float[1] {
t.Fatalf("int_Superior_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior2_Float[0]); text != int_Superior2_Float[1] {
t.Fatalf("int_Superior2_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Superior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior_Bool[0]); text != int_Superior_Bool[1] {
t.Fatalf("int_Superior_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Superior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Superior2_Bool[0]); text != int_Superior2_Bool[1] {
t.Fatalf("int_Superior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Superior2_Bool[1] + Reset + "'")
}
// Float
float_Superior_Str := []string{"#{f/4.5 > 'text'; yes | no}", "yes"}
float_Superior2_Str := []string{"#{f/4.5 > 'texte'; yes | no}", "no"}
float_Superior_Int := []string{"#{f/4.5 > i/4; yes | no}", "yes"}
float_Superior2_Int := []string{"#{f/4.5 > i/5; yes | no}", "no"}
float_Superior_Float := []string{"#{f/4.5 > f/4.4; yes | no}", "yes"}
float_Superior2_Float := []string{"#{f/4.5 > f/4.6; yes | no}", "no"}
float_Superior_Bool := []string{"#{f/4.5 > b/True; yes | no}", "yes"}
float_Superior2_Bool := []string{"#{f/4.5 > b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(float_Superior_Str[0]); text != float_Superior_Str[1] {
t.Fatalf("float_Superior_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior2_Str[0]); text != float_Superior2_Str[1] {
t.Fatalf("float_Superior2_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Superior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Int[0]); text != float_Superior_Int[1] {
t.Fatalf("float_Superior_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior2_Int[0]); text != float_Superior2_Int[1] {
t.Fatalf("float_Superior2_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Superior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Float[0]); text != float_Superior_Float[1] {
t.Fatalf("float_Superior_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior2_Float[0]); text != float_Superior2_Float[1] {
t.Fatalf("float_Superior2_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Superior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior_Bool[0]); text != float_Superior_Bool[1] {
t.Fatalf("float_Superior_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Superior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Superior2_Bool[0]); text != float_Superior2_Bool[1] {
t.Fatalf("float_Superior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Superior2_Bool[1] + Reset + "'")
}
// Bool
bool_Superior_Str := []string{"#{b/True > 'text'; yes | no}", "no"}
bool_Superior2_Str := []string{"#{b/False > 'texte'; yes | no}", "no"}
bool_Superior_Int := []string{"#{b/True > i/4; yes | no}", "no"}
bool_Superior2_Int := []string{"#{b/False > i/5; yes | no}", "no"}
bool_Superior_Float := []string{"#{b/True > f/4.5; yes | no}", "no"}
bool_Superior2_Float := []string{"#{b/False > f/4.6; yes | no}", "no"}
bool_Superior_Bool := []string{"#{b/True > b/True; yes | no}", "no"}
bool_Superior2_Bool := []string{"#{b/False > b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(bool_Superior_Str[0]); text != bool_Superior_Str[1] {
t.Fatalf("bool_Superior_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior2_Str[0]); text != bool_Superior2_Str[1] {
t.Fatalf("bool_Superior2_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Int[0]); text != bool_Superior_Int[1] {
t.Fatalf("bool_Superior_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior2_Int[0]); text != bool_Superior2_Int[1] {
t.Fatalf("bool_Superior2_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Float[0]); text != bool_Superior_Float[1] {
t.Fatalf("bool_Superior_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior2_Float[0]); text != bool_Superior2_Float[1] {
t.Fatalf("bool_Superior2_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior_Bool[0]); text != bool_Superior_Bool[1] {
t.Fatalf("bool_Superior_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Superior2_Bool[0]); text != bool_Superior2_Bool[1] {
t.Fatalf("bool_Superior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Superior2_Bool[1] + Reset + "'")
}
}
func TestConditionInferiorEqual(t *testing.T) {
parser := tem.New(FuncArray{}, varMap)
// String
str_Inferior_Equal_Str := []string{"#{'text' <= 'text'; yes | no}", "yes"}
str_Inferior_Equal2_Str := []string{"#{'text' <= 'texte'; yes | no}", "yes"}
str_Inferior_Equal_Int := []string{"#{'text' <= i/4; yes | no}", "yes"}
str_Inferior_Equal2_Int := []string{"#{'text' <= i/123; yes | no}", "yes"}
str_Inferior_Equal_Float := []string{"#{'text' <= f/4.5; yes | no}", "yes"}
str_Inferior_Equal2_Float := []string{"#{'text' <= f/3.5; yes | no}", "no"}
str_Inferior_Equal_Bool := []string{"#{'text' <= b/True; yes | no}", "no"}
str_Inferior_Equal2_Bool := []string{"#{'text' <= b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(str_Inferior_Equal_Str[0]); text != str_Inferior_Equal_Str[1] {
t.Fatalf("str_Inferior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal2_Str[0]); text != str_Inferior_Equal2_Str[1] {
t.Fatalf("str_Inferior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal_Int[0]); text != str_Inferior_Equal_Int[1] {
t.Fatalf("str_Inferior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal2_Int[0]); text != str_Inferior_Equal2_Int[1] {
t.Fatalf("str_Inferior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal_Float[0]); text != str_Inferior_Equal_Float[1] {
t.Fatalf("str_Inferior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal2_Float[0]); text != str_Inferior_Equal2_Float[1] {
t.Fatalf("str_Inferior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal_Bool[0]); text != str_Inferior_Equal_Bool[1] {
t.Fatalf("str_Inferior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Equal2_Bool[0]); text != str_Inferior_Equal2_Bool[1] {
t.Fatalf("str_Inferior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Equal2_Bool[1] + Reset + "'")
}
// Int
int_Inferior_Equal_Str := []string{"#{i/4 <= 'text'; yes | no}", "yes"}
int_Inferior_Equal2_Str := []string{"#{i/4 <= 'texte'; yes | no}", "yes"}
int_Inferior_Equal_Int := []string{"#{i/4 <= i/4; yes | no}", "yes"}
int_Inferior_Equal2_Int := []string{"#{i/4 <= i/5; yes | no}", "yes"}
int_Inferior_Equal_Float := []string{"#{i/4 <= f/3.5; yes | no}", "no"}
int_Inferior_Equal2_Float := []string{"#{i/4 <= f/4.5; yes | no}", "yes"}
int_Inferior_Equal_Bool := []string{"#{i/4 <= b/True; yes | no}", "no"}
int_Inferior_Equal2_Bool := []string{"#{i/4 <= b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(int_Inferior_Equal_Str[0]); text != int_Inferior_Equal_Str[1] {
t.Fatalf("int_Inferior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal2_Str[0]); text != int_Inferior_Equal2_Str[1] {
t.Fatalf("int_Inferior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal_Int[0]); text != int_Inferior_Equal_Int[1] {
t.Fatalf("int_Inferior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal2_Int[0]); text != int_Inferior_Equal2_Int[1] {
t.Fatalf("int_Inferior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal_Float[0]); text != int_Inferior_Equal_Float[1] {
t.Fatalf("int_Inferior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal2_Float[0]); text != int_Inferior_Equal2_Float[1] {
t.Fatalf("int_Inferior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal_Bool[0]); text != int_Inferior_Equal_Bool[1] {
t.Fatalf("int_Inferior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Equal2_Bool[0]); text != int_Inferior_Equal2_Bool[1] {
t.Fatalf("int_Inferior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Equal2_Bool[1] + Reset + "'")
}
// Float
float_Inferior_Equal_Str := []string{"#{f/4.5 <= 'text'; yes | no}", "no"}
float_Inferior_Equal2_Str := []string{"#{f/4.5 <= 'texte'; yes | no}", "yes"}
float_Inferior_Equal_Int := []string{"#{f/4.5 <= i/4; yes | no}", "no"}
float_Inferior_Equal2_Int := []string{"#{f/4.5 <= i/5; yes | no}", "yes"}
float_Inferior_Equal_Float := []string{"#{f/4.5 <= f/4.4; yes | no}", "no"}
float_Inferior_Equal2_Float := []string{"#{f/4.5 <= f/4.6; yes | no}", "yes"}
float_Inferior_Equal_Bool := []string{"#{f/4.5 <= b/True; yes | no}", "no"}
float_Inferior_Equal2_Bool := []string{"#{f/4.5 <= b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(float_Inferior_Equal_Str[0]); text != float_Inferior_Equal_Str[1] {
t.Fatalf("float_Inferior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal2_Str[0]); text != float_Inferior_Equal2_Str[1] {
t.Fatalf("float_Inferior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal_Int[0]); text != float_Inferior_Equal_Int[1] {
t.Fatalf("float_Inferior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal2_Int[0]); text != float_Inferior_Equal2_Int[1] {
t.Fatalf("float_Inferior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal_Float[0]); text != float_Inferior_Equal_Float[1] {
t.Fatalf("float_Inferior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal2_Float[0]); text != float_Inferior_Equal2_Float[1] {
t.Fatalf("float_Inferior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal_Bool[0]); text != float_Inferior_Equal_Bool[1] {
t.Fatalf("float_Inferior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Equal2_Bool[0]); text != float_Inferior_Equal2_Bool[1] {
t.Fatalf("float_Inferior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Equal2_Bool[1] + Reset + "'")
}
// Bool
bool_Inferior_Equal_Str := []string{"#{b/True <= 'text'; yes | no}", "yes"}
bool_Inferior_Equal2_Str := []string{"#{b/False <= 'texte'; yes | no}", "yes"}
bool_Inferior_Equal_Int := []string{"#{b/True <= i/4; yes | no}", "yes"}
bool_Inferior_Equal2_Int := []string{"#{b/False <= i/5; yes | no}", "yes"}
bool_Inferior_Equal_Float := []string{"#{b/True <= f/4.5; yes | no}", "yes"}
bool_Inferior_Equal2_Float := []string{"#{b/False <= f/4.6; yes | no}", "yes"}
bool_Inferior_Equal_Bool := []string{"#{b/True <= b/True; yes | no}", "yes"}
bool_Inferior_Equal2_Bool := []string{"#{b/False <= b/False; yes | no}", "yes"}
if text, _ := parser.ParseCondition(bool_Inferior_Equal_Str[0]); text != bool_Inferior_Equal_Str[1] {
t.Fatalf("bool_Inferior_Equal_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal2_Str[0]); text != bool_Inferior_Equal2_Str[1] {
t.Fatalf("bool_Inferior_Equal2_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal_Int[0]); text != bool_Inferior_Equal_Int[1] {
t.Fatalf("bool_Inferior_Equal_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal2_Int[0]); text != bool_Inferior_Equal2_Int[1] {
t.Fatalf("bool_Inferior_Equal2_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal_Float[0]); text != bool_Inferior_Equal_Float[1] {
t.Fatalf("bool_Inferior_Equal_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal2_Float[0]); text != bool_Inferior_Equal2_Float[1] {
t.Fatalf("bool_Inferior_Equal2_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal_Bool[0]); text != bool_Inferior_Equal_Bool[1] {
t.Fatalf("bool_Inferior_Equal_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Equal2_Bool[0]); text != bool_Inferior_Equal2_Bool[1] {
t.Fatalf("bool_Inferior_Equal2_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Equal2_Bool[1] + Reset + "'")
}
}
func TestConditionInferior(t *testing.T) {
parser := tem.New(FuncArray{}, varMap)
// String
str_Inferior_Str := []string{"#{'text' < 'text'; yes | no}", "no"}
str_Inferior2_Str := []string{"#{'text' < 'texte'; yes | no}", "yes"}
str_Inferior_Int := []string{"#{'text' < i/4; yes | no}", "no"}
str_Inferior2_Int := []string{"#{'text' < i/123; yes | no}", "yes"}
str_Inferior_Float := []string{"#{'text' < f/4.5; yes | no}", "yes"}
str_Inferior2_Float := []string{"#{'text' < f/3.5; yes | no}", "no"}
str_Inferior_Bool := []string{"#{'text' < b/True; yes | no}", "no"}
str_Inferior2_Bool := []string{"#{'text' < b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(str_Inferior_Str[0]); text != str_Inferior_Str[1] {
t.Fatalf("str_Inferior_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior2_Str[0]); text != str_Inferior2_Str[1] {
t.Fatalf("str_Inferior2_Str : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Int[0]); text != str_Inferior_Int[1] {
t.Fatalf("str_Inferior_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior2_Int[0]); text != str_Inferior2_Int[1] {
t.Fatalf("str_Inferior2_Int : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Float[0]); text != str_Inferior_Float[1] {
t.Fatalf("str_Inferior_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior2_Float[0]); text != str_Inferior2_Float[1] {
t.Fatalf("str_Inferior2_Float : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior_Bool[0]); text != str_Inferior_Bool[1] {
t.Fatalf("str_Inferior_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(str_Inferior2_Bool[0]); text != str_Inferior2_Bool[1] {
t.Fatalf("str_Inferior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + str_Inferior2_Bool[1] + Reset + "'")
}
// Int
int_Inferior_Str := []string{"#{i/4 < 'text'; yes | no}", "no"}
int_Inferior2_Str := []string{"#{i/4 < 'texte'; yes | no}", "yes"}
int_Inferior_Int := []string{"#{i/4 < i/4; yes | no}", "no"}
int_Inferior2_Int := []string{"#{i/4 < i/5; yes | no}", "yes"}
int_Inferior_Float := []string{"#{i/4 < f/3.5; yes | no}", "no"}
int_Inferior2_Float := []string{"#{i/4 < f/4.5; yes | no}", "yes"}
int_Inferior_Bool := []string{"#{i/4 < b/True; yes | no}", "no"}
int_Inferior2_Bool := []string{"#{i/4 < b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(int_Inferior_Str[0]); text != int_Inferior_Str[1] {
t.Fatalf("int_Inferior_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior2_Str[0]); text != int_Inferior2_Str[1] {
t.Fatalf("int_Inferior2_Str : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Int[0]); text != int_Inferior_Int[1] {
t.Fatalf("int_Inferior_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior2_Int[0]); text != int_Inferior2_Int[1] {
t.Fatalf("int_Inferior2_Int : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Float[0]); text != int_Inferior_Float[1] {
t.Fatalf("int_Inferior_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior2_Float[0]); text != int_Inferior2_Float[1] {
t.Fatalf("int_Inferior2_Float : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior_Bool[0]); text != int_Inferior_Bool[1] {
t.Fatalf("int_Inferior_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(int_Inferior2_Bool[0]); text != int_Inferior2_Bool[1] {
t.Fatalf("int_Inferior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + int_Inferior2_Bool[1] + Reset + "'")
}
// Float
float_Inferior_Str := []string{"#{f/4.5 < 'text'; yes | no}", "no"}
float_Inferior2_Str := []string{"#{f/4.5 < 'texte'; yes | no}", "yes"}
float_Inferior_Int := []string{"#{f/4.5 < i/4; yes | no}", "no"}
float_Inferior2_Int := []string{"#{f/4.5 < i/5; yes | no}", "yes"}
float_Inferior_Float := []string{"#{f/4.5 < f/4.5; yes | no}", "no"}
float_Inferior2_Float := []string{"#{f/4.5 < f/4.6; yes | no}", "yes"}
float_Inferior_Bool := []string{"#{f/4.5 < b/True; yes | no}", "no"}
float_Inferior2_Bool := []string{"#{f/4.5 < b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(float_Inferior_Str[0]); text != float_Inferior_Str[1] {
t.Fatalf("float_Inferior_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior2_Str[0]); text != float_Inferior2_Str[1] {
t.Fatalf("float_Inferior2_Str : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Int[0]); text != float_Inferior_Int[1] {
t.Fatalf("float_Inferior_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior2_Int[0]); text != float_Inferior2_Int[1] {
t.Fatalf("float_Inferior2_Int : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Float[0]); text != float_Inferior_Float[1] {
t.Fatalf("float_Inferior_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior2_Float[0]); text != float_Inferior2_Float[1] {
t.Fatalf("float_Inferior2_Float : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior_Bool[0]); text != float_Inferior_Bool[1] {
t.Fatalf("float_Inferior_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(float_Inferior2_Bool[0]); text != float_Inferior2_Bool[1] {
t.Fatalf("float_Inferior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + float_Inferior2_Bool[1] + Reset + "'")
}
// Bool
bool_Inferior_Str := []string{"#{b/True < 'text'; yes | no}", "yes"}
bool_Inferior2_Str := []string{"#{b/False < 'texte'; yes | no}", "yes"}
bool_Inferior_Int := []string{"#{b/True < i/4; yes | no}", "yes"}
bool_Inferior2_Int := []string{"#{b/False < i/5; yes | no}", "yes"}
bool_Inferior_Float := []string{"#{b/True < f/4.5; yes | no}", "yes"}
bool_Inferior2_Float := []string{"#{b/False < f/4.6; yes | no}", "yes"}
bool_Inferior_Bool := []string{"#{b/True < b/True; yes | no}", "no"}
bool_Inferior2_Bool := []string{"#{b/False < b/False; yes | no}", "no"}
if text, _ := parser.ParseCondition(bool_Inferior_Str[0]); text != bool_Inferior_Str[1] {
t.Fatalf("bool_Inferior_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior2_Str[0]); text != bool_Inferior2_Str[1] {
t.Fatalf("bool_Inferior2_Str : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior2_Str[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Int[0]); text != bool_Inferior_Int[1] {
t.Fatalf("bool_Inferior_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior2_Int[0]); text != bool_Inferior2_Int[1] {
t.Fatalf("bool_Inferior2_Int : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior2_Int[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Float[0]); text != bool_Inferior_Float[1] {
t.Fatalf("bool_Inferior_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior2_Float[0]); text != bool_Inferior2_Float[1] {
t.Fatalf("bool_Inferior2_Float : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior2_Float[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior_Bool[0]); text != bool_Inferior_Bool[1] {
t.Fatalf("bool_Inferior_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior_Bool[1] + Reset + "'")
}
if text, _ := parser.ParseCondition(bool_Inferior2_Bool[0]); text != bool_Inferior2_Bool[1] {
t.Fatalf("bool_Inferior2_Bool : '" + Red + text + Reset + "' != '" + Yellow + bool_Inferior2_Bool[1] + Reset + "'")
}
}
func TestSwitch(t *testing.T) {
text_Switch_1 := []string{"?{str; Jame::#0, Tony::#1, Marco::#2, _::#default}", "#0"}
text_Switch_2 := []string{"?{int/int; 56::#0, 36::#1, 32::#2, _::#default}", "#2"}
parser := tem.New(arrayFunc, varMap)
if text, _ := parser.ParseSwitch(text_Switch_1[0]); text != text_Switch_1[1] {
t.Fatalf("text_Switch_1 : '" + Red + text + Reset + "' != '" + Yellow + text_Switch_1[1] + Reset + "'")
}
if text, _ := parser.Parse(text_Switch_2[0]); text != text_Switch_2[1] {
t.Fatalf("text_Switch_2 : '" + Red + text + Reset + "' != '" + Yellow + text_Switch_2[1] + Reset + "'")
}
}
func TestHasOne(t *testing.T) {
text_Has_One_1 := []Any{"?{int/int; 56::#0, 36::#1, 32::#2, _::#default} and ?{int/int; 56::#0, 36::#1, 32::#2, _::#default}", true}
text_Has_One_2 := []Any{"?{int/int; 56::#0, 36::#1, 32::#2, _::#default} and ${bool}", true}
text_Has_One_3 := []Any{"@{uppercase ${var}} and ${name}", true}
text_Has_One_4 := []Any{"text", false}
text_Has_One_5 := []Any{"%{bool}", false}
parser := tem.New(FuncArray{}, VarMap{})
if bool := parser.HasOne(fmt.Sprintf("%v", text_Has_One_1[0])); bool != text_Has_One_1[1] {
t.Fatalf("text_Has_One_1 : '" + Red + fmt.Sprintf("%v", bool) + Reset + "' != '" + Yellow + fmt.Sprintf("%v", text_Has_One_1[1]) + Reset + "'")
}
if bool := parser.HasOne(fmt.Sprintf("%v", text_Has_One_2[0])); bool != text_Has_One_2[1] {
t.Fatalf("text_Has_One_2 : '" + Red + fmt.Sprintf("%v", bool) + Reset + "' != '" + Yellow + fmt.Sprintf("%v", text_Has_One_2[1]) + Reset + "'")
}
if bool := parser.HasOne(fmt.Sprintf("%v", text_Has_One_3[0])); bool != text_Has_One_3[1] {
t.Fatalf("text_Has_One_3 : '" + Red + fmt.Sprintf("%v", bool) + Reset + "' != '" + Yellow + fmt.Sprintf("%v", text_Has_One_3[1]) + Reset + "'")
}
if bool := parser.HasOne(fmt.Sprintf("%v", text_Has_One_4[0])); bool != text_Has_One_4[1] {
t.Fatalf("text_Has_One_4 : '" + Red + fmt.Sprintf("%v", bool) + Reset + "' != '" + Yellow + fmt.Sprintf("%v", text_Has_One_4[1]) + Reset + "'")
}