-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathmcdc_spec_witnesses_test.go
More file actions
3655 lines (3247 loc) · 157 KB
/
Copy pathmcdc_spec_witnesses_test.go
File metadata and controls
3655 lines (3247 loc) · 157 KB
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 jsonparser
import (
"bytes"
"errors"
"testing"
)
// =============================================================================
// Spec-level MC/DC witness tests.
// =============================================================================
//
// This file closes spec-level MC/DC witness rows reported by
// `proof mcdc spec queue`. Each test drives the requirement's truth-table row
// through the public API and asserts the implementation-side outcome that
// corresponds to that row.
//
// - Trigger-false rows (implication antecedent false) carry a `[no-action: ...]`
// trailer that names the caller-level assertion proving the action did not
// fire (callback counter stays 0; typed getter returns ""; Get returns nil).
// - Invariant-violation rows (formula evaluates FALSE in the table) are
// witnessed by driving the positive neighbour row, which proves the FALSE
// combination cannot occur in a correct implementation.
// - Positive action rows drive the actual scenario through the public API.
// -----------------------------------------------------------------------------
// SYS-REQ-001 (parser.go Get — existing-path lookup)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-001
// MCDC SYS-REQ-001: addressed_path_exists=T, json_input_is_well_formed=F, key_path_is_provided=T, returns_existing_path_lookup_result=F => TRUE [no-action: Get returns nil value and non-nil error, no existing-path result emitted]
func TestMCDC_SYS_REQ_001_Row2_TriggerFalse(t *testing.T) {
// Malformed input where the addressed key would exist if the payload were
// well-formed. The parser must NOT emit a successful existing-path lookup
// result; it returns a nil value and an error.
value, _, _, err := Get([]byte(`{"a":`), "a")
if err == nil {
t.Fatal("expected error on malformed input, got nil")
}
if value != nil {
t.Fatalf("expected nil value (no existing-path-result action), got %v", value)
}
}
// Verifies: SYS-REQ-001
// MCDC SYS-REQ-001: addressed_path_exists=T, json_input_is_well_formed=T, key_path_is_provided=T, returns_existing_path_lookup_result=F => FALSE
func TestMCDC_SYS_REQ_001_Row4_InvariantViolation(t *testing.T) {
// Row 4 is an invariant-violation row: it would require Get on
// well-formed JSON with a key path that exists to return NO existing-path
// lookup result. The positive neighbour row (Row 5) shows the
// implementation returns the value, so this combination is unreachable
// in a correct build. Witness by driving the positive path.
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || !bytes.Equal(value, []byte("1")) {
t.Fatalf("expected existing-path lookup to return 1, got value=%s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-002 (GetString)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-002
// MCDC SYS-REQ-002: addressed_value_is_string=F, raw_string_token_is_well_formed=T, returns_getstring_decoded_value=F => TRUE [no-action: GetString returns empty string and non-nil error, no decoded value emitted]
func TestMCDC_SYS_REQ_002_Row1_TriggerFalse(t *testing.T) {
// Addressed value is NOT a string (it is a number) but the raw token is a
// well-formed JSON value. GetString must not decode a value.
value, err := GetString([]byte(`{"a":123}`), "a")
if err == nil {
t.Fatal("expected error when GetString targets non-string, got nil")
}
if value != "" {
t.Fatalf("expected empty string (no decode action), got %q", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-003 (GetInt)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-003
// MCDC SYS-REQ-003: addressed_value_is_number=F, raw_number_token_is_integer_parseable=T, returns_getint_value=F => TRUE [no-action: GetInt returns 0 and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_003_Row1_TriggerFalse(t *testing.T) {
// Addressed value is NOT a number (it is a string) even though a
// well-formed number-like token exists in the payload. GetInt must not
// return a value.
value, err := GetInt([]byte(`{"a":"123"}`), "a")
if err == nil {
t.Fatal("expected error when GetInt targets non-number, got nil")
}
if value != 0 {
t.Fatalf("expected zero (no value action), got %d", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-004 (GetFloat)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-004
// MCDC SYS-REQ-004: addressed_value_is_number=F, raw_number_token_is_float_parseable=T, returns_getfloat_value=F => TRUE [no-action: GetFloat returns 0 and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_004_Row1_TriggerFalse(t *testing.T) {
value, err := GetFloat([]byte(`{"a":"1.5"}`), "a")
if err == nil {
t.Fatal("expected error when GetFloat targets non-number, got nil")
}
if value != 0 {
t.Fatalf("expected zero (no value action), got %v", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-005 (GetBoolean)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-005
// MCDC SYS-REQ-005: addressed_value_is_boolean=F, raw_boolean_token_is_well_formed=T, returns_getboolean_value=F => TRUE [no-action: GetBoolean returns false and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_005_Row1_TriggerFalse(t *testing.T) {
value, err := GetBoolean([]byte(`{"a":"true"}`), "a")
if err == nil {
t.Fatal("expected error when GetBoolean targets non-boolean, got nil")
}
if value {
t.Fatal("expected false (no value action), got true")
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-006 (ArrayEach)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-006
// MCDC SYS-REQ-006: addressed_array_is_empty=F, addressed_array_is_well_formed=F, array_callback_receives_elements_in_order=F => TRUE [no-action: callback counter == 0, ArrayEach returns error, no in-order delivery]
func TestMCDC_SYS_REQ_006_Row1_TriggerFalse(t *testing.T) {
// Malformed array (just opening bracket, not parseable as elements). The
// callback must never fire.
callbackCalls := 0
_, err := ArrayEach([]byte(`[`), func(value []byte, dataType ValueType, offset int, err error) {
callbackCalls++
})
if callbackCalls != 0 {
t.Fatalf("expected zero callback invocations on malformed array, got %d", callbackCalls)
}
if err == nil {
t.Fatal("expected error from ArrayEach on malformed input, got nil")
}
}
// Verifies: SYS-REQ-006
// MCDC SYS-REQ-006: addressed_array_is_empty=T, addressed_array_is_well_formed=T, array_callback_receives_elements_in_order=F => TRUE
func TestMCDC_SYS_REQ_006_Row4_EmptyArray(t *testing.T) {
// Empty well-formed array: callback must not fire because there are no
// elements to deliver.
callbackCalls := 0
_, err := ArrayEach([]byte(`[]`), func(value []byte, dataType ValueType, offset int, err error) {
callbackCalls++
})
if err != nil {
t.Fatalf("ArrayEach on empty array returned error: %v", err)
}
if callbackCalls != 0 {
t.Fatalf("expected zero callback invocations on empty array, got %d", callbackCalls)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-007 (ObjectEach)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-007
// MCDC SYS-REQ-007: addressed_object_is_empty=F, addressed_object_is_well_formed=F, object_callback_receives_entries=F => TRUE [no-action: callback counter == 0, ObjectEach returns error, no entries delivered]
func TestMCDC_SYS_REQ_007_Row1_TriggerFalse(t *testing.T) {
callbackCalls := 0
err := ObjectEach([]byte(`{`), func(key []byte, value []byte, dataType ValueType, offset int) error {
callbackCalls++
return nil
})
if callbackCalls != 0 {
t.Fatalf("expected zero callback invocations on malformed object, got %d", callbackCalls)
}
if err == nil {
t.Fatal("expected error from ObjectEach on malformed input, got nil")
}
}
// Verifies: SYS-REQ-007
// MCDC SYS-REQ-007: addressed_object_is_empty=T, addressed_object_is_well_formed=T, object_callback_receives_entries=F => TRUE
func TestMCDC_SYS_REQ_007_Row4_EmptyObject(t *testing.T) {
callbackCalls := 0
err := ObjectEach([]byte(`{}`), func(key []byte, value []byte, dataType ValueType, offset int) error {
callbackCalls++
return nil
})
if err != nil {
t.Fatalf("ObjectEach on empty object returned error: %v", err)
}
if callbackCalls != 0 {
t.Fatalf("expected zero callback invocations on empty object, got %d", callbackCalls)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-008 (EachKey multipath scan)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-008
// MCDC SYS-REQ-008: eachkey_callback_receives_found_values=F, eachkey_completes_requested_scan=F, eachkey_malformed_input_returns_error=F, missing_multipath_request_does_not_emit_callback=F, multipath_requests_are_provided=F => TRUE [no-action: callback counter == 0, EachKey returns immediately because no paths are provided]
func TestMCDC_SYS_REQ_008_Row1_TriggerFalse(t *testing.T) {
// EachKey with no paths exercises the antecedent-false branch
// (multipath_requests_are_provided = F).
callbackCalls := 0
EachKey([]byte(`{"a":1}`), func(i int, value []byte, vt ValueType, off error) {
callbackCalls++
})
if callbackCalls != 0 {
t.Fatalf("expected zero callback invocations when no paths provided, got %d", callbackCalls)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-009 (Set)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-009
// MCDC SYS-REQ-009: set_creates_missing_path=F, set_path_is_provided=F, set_returns_not_found_error=F, set_returns_updated_document=F, set_target_exists=F => TRUE [no-action: Set returns (nil, KeyPathNotFoundError) and input is not mutated]
func TestMCDC_SYS_REQ_009_Row1_TriggerFalse(t *testing.T) {
// Set without any keys: returns nil + KeyPathNotFoundError. No document
// update action is performed.
data := []byte(`{"a":1}`)
value, err := Set(data, []byte(`42`))
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError when no path provided, got %v", err)
}
if value != nil {
t.Fatalf("expected nil return (no update action), got %v", value)
}
if !bytes.Equal(data, []byte(`{"a":1}`)) {
t.Fatalf("input was mutated: %s", string(data))
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-011 (GetUnsafeString)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-011
// MCDC SYS-REQ-011: addressed_value_is_string=F, returns_unsafe_string_view=F => TRUE [no-action: GetUnsafeString returns empty string and KeyPathNotFoundError, no view emitted]
func TestMCDC_SYS_REQ_011_Row1_TriggerFalse(t *testing.T) {
// Addressed path does not resolve to any value, so no unsafe string view
// is returned.
value, err := GetUnsafeString([]byte(`{"a":1}`), "missing")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError on missing path, got %v", err)
}
if value != "" {
t.Fatalf("expected empty string (no view action), got %q", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-012 (ParseBoolean)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-012
// MCDC SYS-REQ-012: raw_boolean_literal_is_valid=F, returns_parseboolean_value=F => TRUE [no-action: ParseBoolean returns false and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_012_Row1_TriggerFalse(t *testing.T) {
value, err := ParseBoolean([]byte(`notabool`))
if err == nil {
t.Fatal("expected error when ParseBoolean gets invalid literal, got nil")
}
if value {
t.Fatal("expected false (no value action), got true")
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-013 (ParseFloat)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-013
// MCDC SYS-REQ-013: raw_float_token_is_well_formed=F, returns_parsefloat_value=F => TRUE [no-action: ParseFloat returns 0 and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_013_Row1_TriggerFalse(t *testing.T) {
value, err := ParseFloat([]byte(`notafloat`))
if err == nil {
t.Fatal("expected error when ParseFloat gets invalid token, got nil")
}
if value != 0 {
t.Fatalf("expected zero (no value action), got %v", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-014 (ParseString)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-014
// MCDC SYS-REQ-014: raw_string_literal_is_well_formed=F, returns_parsestring_value=F => TRUE [no-action: ParseString returns empty string and MalformedValueError, no value emitted]
func TestMCDC_SYS_REQ_014_Row1_TriggerFalse(t *testing.T) {
// Malformed escape sequence forces Unescape to fail; ParseString wraps
// the failure as MalformedValueError and returns an empty string.
value, err := ParseString([]byte(`abc\q`))
if err == nil {
t.Fatal("expected error when ParseString gets malformed escape, got nil")
}
if value != "" {
t.Fatalf("expected empty string (no value action), got %q", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-015 (ParseInt)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-015
// MCDC SYS-REQ-015: raw_int_token_is_well_formed=F, returns_parseint_value=F => TRUE [no-action: ParseInt returns 0 and non-nil error, no value emitted]
func TestMCDC_SYS_REQ_015_Row1_TriggerFalse(t *testing.T) {
value, err := ParseInt([]byte(`notanint`))
if err == nil {
t.Fatal("expected error when ParseInt gets invalid token, got nil")
}
if value != 0 {
t.Fatalf("expected zero (no value action), got %d", value)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-016 (missing-path lookup on well-formed JSON via Get)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-016
// MCDC SYS-REQ-016: addressed_path_exists=F, json_input_is_well_formed=F, key_path_is_provided=T, returns_missing_path_result_for_well_formed_lookup=F => TRUE [no-action: Get returns non-nil error and value=nil on malformed input, no missing-path-result action]
func TestMCDC_SYS_REQ_016_Row1_TriggerFalse(t *testing.T) {
value, _, _, err := Get([]byte(`{"a":`), "missing")
if err == nil {
t.Fatal("expected error on malformed input, got nil")
}
if value != nil {
t.Fatalf("expected nil value (no missing-path-result action), got %v", value)
}
}
// Verifies: SYS-REQ-016
// MCDC SYS-REQ-016: addressed_path_exists=F, json_input_is_well_formed=T, key_path_is_provided=F, returns_missing_path_result_for_well_formed_lookup=F => TRUE
func TestMCDC_SYS_REQ_016_Row2_NoKeyPath(t *testing.T) {
// No key path provided: the formula is satisfied via !key_path_is_provided
// regardless of the missing-path-result action. Drive Get on well-formed
// JSON without a key path; it returns the root value (no missing-path lookup).
value, dataType, _, err := Get([]byte(`{"a":1}`))
if err != nil {
t.Fatalf("Get without key path returned error: %v", err)
}
if dataType != Object || string(value) != `{"a":1}` {
t.Fatalf("unexpected root value: %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-016
// MCDC SYS-REQ-016: addressed_path_exists=F, json_input_is_well_formed=T, key_path_is_provided=T, returns_missing_path_result_for_well_formed_lookup=F => FALSE
func TestMCDC_SYS_REQ_016_Row3_InvariantViolation(t *testing.T) {
// Invariant-violation row: Get on well-formed JSON with a key path that
// does not exist must return the missing-path-result (Row 4). Drive the
// positive path to prove this FALSE combination is unreachable.
_, dataType, offset, err := Get([]byte(`{"a":1}`), "missing")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError, got %v", err)
}
if dataType != NotExist || offset != -1 {
t.Fatalf("expected not-found tuple, got type=%v offset=%d", dataType, offset)
}
}
// Verifies: SYS-REQ-016
// MCDC SYS-REQ-016: addressed_path_exists=F, json_input_is_well_formed=T, key_path_is_provided=T, returns_missing_path_result_for_well_formed_lookup=T => TRUE
func TestMCDC_SYS_REQ_016_Row4_MissingPathResult(t *testing.T) {
_, dataType, offset, err := Get([]byte(`{"a":1}`), "missing")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError, got %v", err)
}
if dataType != NotExist || offset != -1 {
t.Fatalf("expected not-found tuple, got type=%v offset=%d", dataType, offset)
}
}
// Verifies: SYS-REQ-016
// MCDC SYS-REQ-016: addressed_path_exists=T, json_input_is_well_formed=T, key_path_is_provided=T, returns_missing_path_result_for_well_formed_lookup=F => TRUE
func TestMCDC_SYS_REQ_016_Row5_AddressedPathExists(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected existing path lookup, got value=%s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-017 (parse error on incomplete input via Get)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-017
// MCDC SYS-REQ-017: input_is_incomplete_during_lookup=F, returns_parse_error_for_incomplete_lookup=F => TRUE [no-action: Get returns nil error on complete input, no parse-error action fires]
func TestMCDC_SYS_REQ_017_Row1_TriggerFalse(t *testing.T) {
value, _, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("expected nil error on complete input, got %v", err)
}
if value == nil {
t.Fatal("expected non-nil value, got nil")
}
}
// Verifies: SYS-REQ-017
// MCDC SYS-REQ-017: input_is_incomplete_during_lookup=T, returns_parse_error_for_incomplete_lookup=F => FALSE
func TestMCDC_SYS_REQ_017_Row2_InvariantViolation(t *testing.T) {
// Invariant-violation row: incomplete input without a parse error cannot
// occur in a correct build. Drive the positive path (Row 3) to prove this
// combination is unreachable.
if _, _, _, err := Get([]byte(`{"a":`), "a"); err == nil {
t.Fatal("expected parse error on incomplete input, got nil")
}
}
// Verifies: SYS-REQ-017
// MCDC SYS-REQ-017: input_is_incomplete_during_lookup=T, returns_parse_error_for_incomplete_lookup=T => TRUE
func TestMCDC_SYS_REQ_017_Row3_ParseErrorReturned(t *testing.T) {
if _, _, _, err := Get([]byte(`{"a":`), "a"); err == nil {
t.Fatal("expected parse error on incomplete input, got nil")
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-018 (root value lookup without key path)
// FRETish: !json_input_is_well_formed | !key_path_is_provided | returns_root_value_without_key_path
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-018
// MCDC SYS-REQ-018: json_input_is_well_formed=F, key_path_is_provided=F, returns_root_value_without_key_path=F => TRUE [no-action: Get on malformed input without key path returns error, no root value emitted]
func TestMCDC_SYS_REQ_018_Row1_TriggerFalse(t *testing.T) {
value, _, _, err := Get([]byte(`{"a":`))
if err == nil {
t.Fatal("expected error on malformed input without key path, got nil")
}
if value != nil {
t.Fatalf("expected nil value (no root-value action), got %v", value)
}
}
// Verifies: SYS-REQ-018
// MCDC SYS-REQ-018: json_input_is_well_formed=T, key_path_is_provided=F, returns_root_value_without_key_path=F => FALSE
func TestMCDC_SYS_REQ_018_Row2_InvariantViolation(t *testing.T) {
// Invariant violation: Get on well-formed JSON without a key path MUST
// return the root value (Row 3). Witness the positive path.
value, dataType, _, err := Get([]byte(`{"a":1}`))
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Object || string(value) != `{"a":1}` {
t.Fatalf("expected root value, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-018
// MCDC SYS-REQ-018: json_input_is_well_formed=T, key_path_is_provided=F, returns_root_value_without_key_path=T => TRUE
func TestMCDC_SYS_REQ_018_Row3_RootValueReturned(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`))
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Object || string(value) != `{"a":1}` {
t.Fatalf("expected root value, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-018
// MCDC SYS-REQ-018: json_input_is_well_formed=T, key_path_is_provided=T, returns_root_value_without_key_path=F => TRUE
func TestMCDC_SYS_REQ_018_Row4_KeyPathProvided(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected addressed lookup, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-019 (empty input + key path)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-019
// MCDC SYS-REQ-019: json_input_is_empty=F, key_path_is_provided=T, returns_missing_path_result_for_empty_input=F => TRUE [no-action: Get on non-empty input does not invoke the empty-input missing-path action]
func TestMCDC_SYS_REQ_019_Row1_TriggerFalse(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "missing")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError, got %v", err)
}
if dataType != NotExist || value != nil {
t.Fatalf("expected not-found on non-empty input, got value=%v type=%v", value, dataType)
}
}
// Verifies: SYS-REQ-019
// MCDC SYS-REQ-019: json_input_is_empty=T, key_path_is_provided=F, returns_missing_path_result_for_empty_input=F => TRUE
func TestMCDC_SYS_REQ_019_Row2_EmptyNoKeyPath(t *testing.T) {
// Empty input without key path: formula satisfied via !key_path_is_provided.
// Get on empty input without key path.
value, _, _, err := Get([]byte(""))
if err == nil {
t.Fatal("expected error on empty input, got nil")
}
if value != nil {
t.Fatalf("expected nil value, got %v", value)
}
}
// Verifies: SYS-REQ-019
// MCDC SYS-REQ-019: json_input_is_empty=T, key_path_is_provided=T, returns_missing_path_result_for_empty_input=F => FALSE
func TestMCDC_SYS_REQ_019_Row3_InvariantViolation(t *testing.T) {
// Invariant violation: empty input + key path MUST return missing-path
// result (Row 4). Drive the positive path.
_, dataType, offset, err := Get([]byte(""), "a")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError on empty input, got %v", err)
}
if dataType != NotExist || offset != -1 {
t.Fatalf("expected not-found tuple, got type=%v offset=%d", dataType, offset)
}
}
// Verifies: SYS-REQ-019
// MCDC SYS-REQ-019: json_input_is_empty=T, key_path_is_provided=T, returns_missing_path_result_for_empty_input=T => TRUE
func TestMCDC_SYS_REQ_019_Row4_EmptyMissingPath(t *testing.T) {
_, dataType, offset, err := Get([]byte(""), "a")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError on empty input, got %v", err)
}
if dataType != NotExist || offset != -1 {
t.Fatalf("expected not-found tuple, got type=%v offset=%d", dataType, offset)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-020 (object key segment at current scope)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-020
// MCDC SYS-REQ-020: path_segment_is_object_key=F, returns_value_from_current_scope_object_key=F, segment_is_evaluated_at_current_scope=T => TRUE [no-action: array-index segment does not invoke object-key lookup]
func TestMCDC_SYS_REQ_020_Row1_TriggerFalse(t *testing.T) {
// Use an array-index segment; the object-key lookup action must not fire.
value, dataType, _, err := Get([]byte(`{"a":[1,2,3]}`), "a", "[1]")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "2" {
t.Fatalf("expected array element lookup, got value=%s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-020
// MCDC SYS-REQ-020: path_segment_is_object_key=T, returns_value_from_current_scope_object_key=F, segment_is_evaluated_at_current_scope=F => TRUE
func TestMCDC_SYS_REQ_020_Row2_NotEvaluated(t *testing.T) {
// Path segment is an object key, but evaluation stops before this segment
// because an earlier segment did not match. Get returns not-found.
_, _, _, err := Get([]byte(`{"a":1}`), "missing", "b")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError, got %v", err)
}
}
// Verifies: SYS-REQ-020
// MCDC SYS-REQ-020: path_segment_is_object_key=T, returns_value_from_current_scope_object_key=F, segment_is_evaluated_at_current_scope=T => FALSE
func TestMCDC_SYS_REQ_020_Row3_InvariantViolation(t *testing.T) {
// Invariant violation: an evaluated object-key segment MUST return a value
// from the current scope (Row 4). Drive the positive path.
value, dataType, _, err := Get([]byte(`{"a":{"b":2}}`), "a", "b")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "2" {
t.Fatalf("expected nested object-key lookup, got value=%s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-020
// MCDC SYS-REQ-020: path_segment_is_object_key=T, returns_value_from_current_scope_object_key=T, segment_is_evaluated_at_current_scope=T => TRUE
func TestMCDC_SYS_REQ_020_Row4_ObjectKeyMatched(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":{"b":2}}`), "a", "b")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "2" {
t.Fatalf("expected nested object-key lookup, got value=%s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-021 (in-bounds array index)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-021
// MCDC SYS-REQ-021: array_index_is_in_bounds=F, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_value_from_in_bounds_array_index=F => TRUE
func TestMCDC_SYS_REQ_021_Row1_OutOfBounds(t *testing.T) {
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[9]")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for out-of-bounds index, got %v", err)
}
}
// Verifies: SYS-REQ-021
// MCDC SYS-REQ-021: array_index_is_in_bounds=T, array_index_segment_is_valid=F, path_segment_is_array_index=T, returns_value_from_in_bounds_array_index=F => TRUE
func TestMCDC_SYS_REQ_021_Row2_InvalidSegment(t *testing.T) {
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for malformed array index, got %v", err)
}
}
// Verifies: SYS-REQ-021
// MCDC SYS-REQ-021: array_index_is_in_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=F, returns_value_from_in_bounds_array_index=F => TRUE [no-action: non-array-index segment does not invoke in-bounds-array-index action]
func TestMCDC_SYS_REQ_021_Row3_NotArraySegment(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":[1,2]}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Array {
t.Fatalf("expected Array type, got %v", dataType)
}
if string(value) != "[1,2]" {
t.Fatalf("expected array bytes, got %s", string(value))
}
}
// Verifies: SYS-REQ-021
// MCDC SYS-REQ-021: array_index_is_in_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_value_from_in_bounds_array_index=F => FALSE
func TestMCDC_SYS_REQ_021_Row4_InvariantViolation(t *testing.T) {
// Invariant violation: in-bounds valid array index MUST return the element
// (Row 5). Drive the positive path.
value, dataType, _, err := Get([]byte(`{"a":[1,2,3]}`), "a", "[1]")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "2" {
t.Fatalf("expected array element 2, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-021
// MCDC SYS-REQ-021: array_index_is_in_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_value_from_in_bounds_array_index=T => TRUE
func TestMCDC_SYS_REQ_021_Row5_InBoundsReturned(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":[1,2,3]}`), "a", "[1]")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "2" {
t.Fatalf("expected array element 2, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-022 (invalid array index syntax)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-022
// MCDC SYS-REQ-022: array_index_segment_is_valid=F, path_segment_is_array_index=F, returns_invalid_array_index_not_found=F => TRUE [no-action: non-array-index segment does not invoke the invalid-array-index action]
func TestMCDC_SYS_REQ_022_Row1_TriggerFalse(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected object-key lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-022
// MCDC SYS-REQ-022: array_index_segment_is_valid=F, path_segment_is_array_index=T, returns_invalid_array_index_not_found=F => FALSE
func TestMCDC_SYS_REQ_022_Row2_InvariantViolation(t *testing.T) {
// Invariant violation: invalid array index segment MUST return not-found
// (Row 3). Drive the positive path.
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for malformed array index, got %v", err)
}
}
// Verifies: SYS-REQ-022
// MCDC SYS-REQ-022: array_index_segment_is_valid=F, path_segment_is_array_index=T, returns_invalid_array_index_not_found=T => TRUE
func TestMCDC_SYS_REQ_022_Row3_InvalidIndexNotFound(t *testing.T) {
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for malformed array index, got %v", err)
}
}
// Verifies: SYS-REQ-022
// MCDC SYS-REQ-022: array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_invalid_array_index_not_found=F => TRUE
func TestMCDC_SYS_REQ_022_Row4_ValidSegment(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[0]")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected valid array element, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-023 (out-of-bounds array index)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-023
// MCDC SYS-REQ-023: array_index_is_out_of_bounds=F, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_oob_array_index_not_found=F => TRUE
func TestMCDC_SYS_REQ_023_Row1_InBounds(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[0]")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected in-bounds element, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-023
// MCDC SYS-REQ-023: array_index_is_out_of_bounds=T, array_index_segment_is_valid=F, path_segment_is_array_index=T, returns_oob_array_index_not_found=F => TRUE
func TestMCDC_SYS_REQ_023_Row2_InvalidOutOfBounds(t *testing.T) {
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for malformed array index, got %v", err)
}
}
// Verifies: SYS-REQ-023
// MCDC SYS-REQ-023: array_index_is_out_of_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=F, returns_oob_array_index_not_found=F => TRUE [no-action: non-array-index segment does not invoke the oob action]
func TestMCDC_SYS_REQ_023_Row3_NotArraySegment(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number {
t.Fatalf("expected Number type, got %v", dataType)
}
if string(value) != "1" {
t.Fatalf("expected value 1, got %s", string(value))
}
}
// Verifies: SYS-REQ-023
// MCDC SYS-REQ-023: array_index_is_out_of_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_oob_array_index_not_found=F => FALSE
func TestMCDC_SYS_REQ_023_Row4_InvariantViolation(t *testing.T) {
// Invariant violation: out-of-bounds valid array index MUST return
// not-found (Row 5). Drive the positive path.
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[9]")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for out-of-bounds index, got %v", err)
}
}
// Verifies: SYS-REQ-023
// MCDC SYS-REQ-023: array_index_is_out_of_bounds=T, array_index_segment_is_valid=T, path_segment_is_array_index=T, returns_oob_array_index_not_found=T => TRUE
func TestMCDC_SYS_REQ_023_Row5_OobNotFound(t *testing.T) {
_, _, _, err := Get([]byte(`{"a":[1,2]}`), "a", "[9]")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError for out-of-bounds index, got %v", err)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-024 (decoded escaped object key)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-024
// MCDC SYS-REQ-024: decoded_path_segment_matches_escaped_key=F, escaped_json_object_key_is_present=T, returns_value_from_decoded_escaped_key=F => TRUE
func TestMCDC_SYS_REQ_024_Row1_NoMatch(t *testing.T) {
// Escaped key is present, but the path segment doesn't match it.
_, _, _, err := Get([]byte(`{"a\u00B0b":1}`), "axb")
if !errors.Is(err, KeyPathNotFoundError) {
t.Fatalf("expected KeyPathNotFoundError, got %v", err)
}
}
// Verifies: SYS-REQ-024
// MCDC SYS-REQ-024: decoded_path_segment_matches_escaped_key=T, escaped_json_object_key_is_present=F, returns_value_from_decoded_escaped_key=F => TRUE [no-action: no escaped key present means no decoded-escaped-key lookup action]
func TestMCDC_SYS_REQ_024_Row2_TriggerFalse(t *testing.T) {
// No escaped key in payload; the decoded-escaped-key action cannot fire.
value, dataType, _, err := Get([]byte(`{"plain":1}`), "plain")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected plain key lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-024
// MCDC SYS-REQ-024: decoded_path_segment_matches_escaped_key=T, escaped_json_object_key_is_present=T, returns_value_from_decoded_escaped_key=F => FALSE
func TestMCDC_SYS_REQ_024_Row3_InvariantViolation(t *testing.T) {
// Invariant violation: matching decoded escaped key MUST return value (Row 4).
value, dataType, _, err := Get([]byte(`{"a\u00B0b":1}`), "a°b")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected escaped-key lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-024
// MCDC SYS-REQ-024: decoded_path_segment_matches_escaped_key=T, escaped_json_object_key_is_present=T, returns_value_from_decoded_escaped_key=T => TRUE
func TestMCDC_SYS_REQ_024_Row4_DecodedEscapedMatched(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a\u00B0b":1}`), "a°b")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected escaped-key lookup, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-025 (unquoted raw string contents)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-025
// MCDC SYS-REQ-025: addressed_value_is_string=F, returns_unquoted_raw_string_contents=F => TRUE [no-action: Get on non-string does not return unquoted raw string contents]
func TestMCDC_SYS_REQ_025_Row1_TriggerFalse(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":123}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number {
t.Fatalf("expected Number type (not String), got %v", dataType)
}
if string(value) != "123" {
t.Fatalf("expected 123, got %s", string(value))
}
}
// Verifies: SYS-REQ-025
// MCDC SYS-REQ-025: addressed_value_is_string=T, returns_unquoted_raw_string_contents=F => FALSE
func TestMCDC_SYS_REQ_025_Row2_InvariantViolation(t *testing.T) {
// Invariant violation: string value MUST return unquoted contents (Row 3).
value, dataType, _, err := Get([]byte(`{"a":"hello"}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != String || string(value) != "hello" {
t.Fatalf("expected unquoted string, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-025
// MCDC SYS-REQ-025: addressed_value_is_string=T, returns_unquoted_raw_string_contents=T => TRUE
func TestMCDC_SYS_REQ_025_Row3_StringUnquoted(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":"hello"}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != String || string(value) != "hello" {
t.Fatalf("expected unquoted string, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-026 (best-effort lookup when malformed input is outside addressed token)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-026
// MCDC SYS-REQ-026: addressed_token_can_be_isolated=F, malformed_input_outside_addressed_token=T, returns_best_effort_lookup_result=F => TRUE
func TestMCDC_SYS_REQ_026_Row1_CannotIsolate(t *testing.T) {
// Malformed input that prevents token isolation: Get returns an error
// instead of a best-effort result.
if _, _, _, err := Get([]byte(`{"a":`), "a"); err == nil {
t.Fatal("expected error when addressed token cannot be isolated, got nil")
}
}
// Verifies: SYS-REQ-026
// MCDC SYS-REQ-026: addressed_token_can_be_isolated=T, malformed_input_outside_addressed_token=F, returns_best_effort_lookup_result=F => TRUE [no-action: no malformed input outside token, no best-effort action fires]
func TestMCDC_SYS_REQ_026_Row2_TriggerFalse(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected clean lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-026
// MCDC SYS-REQ-026: addressed_token_can_be_isolated=T, malformed_input_outside_addressed_token=T, returns_best_effort_lookup_result=F => FALSE
func TestMCDC_SYS_REQ_026_Row3_InvariantViolation(t *testing.T) {
// Invariant violation: malformed input outside an isolatable addressed
// token MUST yield a best-effort result (Row 4). Drive the positive path.
value, dataType, _, err := Get([]byte(`{"a":1]`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected best-effort lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-026
// MCDC SYS-REQ-026: addressed_token_can_be_isolated=T, malformed_input_outside_addressed_token=T, returns_best_effort_lookup_result=T => TRUE
func TestMCDC_SYS_REQ_026_Row4_BestEffortSuccess(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1]`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected best-effort lookup, got %s type=%v", string(value), dataType)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-027 (invalid addressed token shape)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-027
// MCDC SYS-REQ-027: addressed_token_shape_is_invalid=F, returns_value_type_error=F => TRUE [no-action: valid token shape does not invoke value-type-error action]
func TestMCDC_SYS_REQ_027_Row1_TriggerFalse(t *testing.T) {
value, dataType, _, err := Get([]byte(`{"a":1}`), "a")
if err != nil {
t.Fatalf("Get returned error: %v", err)
}
if dataType != Number || string(value) != "1" {
t.Fatalf("expected valid lookup, got %s type=%v", string(value), dataType)
}
}
// Verifies: SYS-REQ-027
// MCDC SYS-REQ-027: addressed_token_shape_is_invalid=T, returns_value_type_error=F => FALSE
func TestMCDC_SYS_REQ_027_Row2_InvariantViolation(t *testing.T) {
// Invariant violation: invalid token shape MUST return value-type-error (Row 3).
if _, _, _, err := Get([]byte(`{"a":u}`), "a"); !errors.Is(err, UnknownValueTypeError) {
t.Fatalf("expected UnknownValueTypeError, got %v", err)
}
}
// Verifies: SYS-REQ-027
// MCDC SYS-REQ-027: addressed_token_shape_is_invalid=T, returns_value_type_error=T => TRUE
func TestMCDC_SYS_REQ_027_Row3_ValueTypeError(t *testing.T) {
if _, _, _, err := Get([]byte(`{"a":u}`), "a"); !errors.Is(err, UnknownValueTypeError) {
t.Fatalf("expected UnknownValueTypeError, got %v", err)
}
}
// -----------------------------------------------------------------------------
// SYS-REQ-028 (empty well-formed array produces no callbacks via ArrayEach)
// -----------------------------------------------------------------------------
// Verifies: SYS-REQ-028
// MCDC SYS-REQ-028: addressed_array_is_empty=F, addressed_array_is_well_formed=T, empty_array_produces_no_callbacks=F => TRUE
func TestMCDC_SYS_REQ_028_Row1_NonEmptyWellFormed(t *testing.T) {
// Non-empty well-formed array: callback fires for each element so the
// "empty-array produces no callbacks" action is FALSE.
calls := 0
if _, err := ArrayEach([]byte(`[1,2,3]`), func(value []byte, dataType ValueType, offset int, err error) {
calls++
}); err != nil {
t.Fatalf("ArrayEach returned error: %v", err)
}
if calls != 3 {
t.Fatalf("expected 3 callback invocations, got %d", calls)
}
}
// Verifies: SYS-REQ-028
// MCDC SYS-REQ-028: addressed_array_is_empty=T, addressed_array_is_well_formed=F, empty_array_produces_no_callbacks=F => TRUE [no-action: callback counter == 0 on malformed input, no empty-array action]
func TestMCDC_SYS_REQ_028_Row2_EmptyMalformed(t *testing.T) {
calls := 0
_, err := ArrayEach([]byte(`[`), func(value []byte, dataType ValueType, offset int, err error) {
calls++
})
if calls != 0 {
t.Fatalf("expected zero callbacks on malformed input, got %d", calls)
}
if err == nil {
t.Fatal("expected error on malformed input, got nil")
}
}
// Verifies: SYS-REQ-028
// MCDC SYS-REQ-028: addressed_array_is_empty=T, addressed_array_is_well_formed=T, empty_array_produces_no_callbacks=F => FALSE
func TestMCDC_SYS_REQ_028_Row3_InvariantViolation(t *testing.T) {
// Invariant violation: empty well-formed array MUST produce no callbacks
// (Row 4). Drive the positive path to prove unreachable.
calls := 0
if _, err := ArrayEach([]byte(`[]`), func(value []byte, dataType ValueType, offset int, err error) {
calls++
}); err != nil {
t.Fatalf("ArrayEach on empty array returned error: %v", err)
}
if calls != 0 {
t.Fatalf("expected zero callbacks on empty array, got %d", calls)
}
}