json.should 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

cat demo/tests/concepts.json

# Testing json output with regular should tests is not very convenient

$ Regular text,
rl1:directions.*east

# With the 'j' modifier, data is interpreted as a json file

$ With 'j' and a single ':', tests are on the keys
j:concepts.directions 
j:concepts.wuxing.earth
j0:concepts.winds   
j:numbers[3].meaning
16 17
j:numbers[4][0]
j0:numbers[4][4]
18
j0:numbers[0].meaning
19
j0:numbers[42].meaning
20 21 22 23 24 25 26 27 28 29
  
$ Tests can further be on number of elements in arrays and objects
j>2:numbers
j<7:concepts.winds
j4:concepts.directions        
j5:concepts.wuxing

$ With a second ':', an expression is tested on the values
j:numbers:12
j:concepts.directions:rth
30 31
j:concepts.directions[0]:rth
j0:concepts.directions[3]:rth
32
j0:concepts.wuxing:st
33
j:numbers[4][1]:0.8
34 35 36 37 38 39 40 41 42 43 44 45 46 47

$ The number of matching expressions can also be tested
j2:concepts.directions:st    
j<7:concepts.winds:foo

$ Ignore case ('i') and regular expressions ('r') apply to the expression
ji:concepts.directions:RtH
jr:concepts.directions:no.th
jr>1:concepts.directions:e.*?st


$ Data that are not parsed as json yield 0 occurrences
echo "hello, world"
j0:hello