/ Check-in [daff4832]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:New test cases for the json1 extension.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: daff4832af963f98bcc1d2c2f84bd815d384f850
User & Date: drh 2015-08-29 18:30:30
Context
2015-08-29
19:03
Link the json1 extension into the command-line shell by default. check-in: 2e8e239c user: drh tags: trunk
18:30
New test cases for the json1 extension. check-in: daff4832 user: drh tags: trunk
17:22
Fix the build with -DSQLITE_OMIT_VIRTUALTABLE. check-in: 752918de user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/json101.test.

   108    108   #
   109    109   do_execsql_test json-4.10 {
   110    110     SELECT count(*) FROM j1 WHERE json_type(x) IN ('object','array');
   111    111     SELECT x FROM j1
   112    112      WHERE json_extract(x,'$')<>x
   113    113        AND json_type(x) IN ('object','array');
   114    114   } {4}
          115  +
          116  +do_execsql_test json-5.1 {
          117  +  CREATE TABLE j2(id INTEGER PRIMARY KEY, json, src);
          118  +  INSERT INTO j2(id,json,src)
          119  +  VALUES(1,'{
          120  +    "firstName": "John",
          121  +    "lastName": "Smith",
          122  +    "isAlive": true,
          123  +    "age": 25,
          124  +    "address": {
          125  +      "streetAddress": "21 2nd Street",
          126  +      "city": "New York",
          127  +      "state": "NY",
          128  +      "postalCode": "10021-3100"
          129  +    },
          130  +    "phoneNumbers": [
          131  +      {
          132  +        "type": "home",
          133  +        "number": "212 555-1234"
          134  +      },
          135  +      {
          136  +        "type": "office",
          137  +        "number": "646 555-4567"
          138  +      }
          139  +    ],
          140  +    "children": [],
          141  +    "spouse": null
          142  +  }','https://en.wikipedia.org/wiki/JSON');
          143  +  INSERT INTO j2(id,json,src)
          144  +  VALUES(2, '{
          145  +	"id": "0001",
          146  +	"type": "donut",
          147  +	"name": "Cake",
          148  +	"ppu": 0.55,
          149  +	"batters":
          150  +		{
          151  +			"batter":
          152  +				[
          153  +					{ "id": "1001", "type": "Regular" },
          154  +					{ "id": "1002", "type": "Chocolate" },
          155  +					{ "id": "1003", "type": "Blueberry" },
          156  +					{ "id": "1004", "type": "Devil''s Food" }
          157  +				]
          158  +		},
          159  +	"topping":
          160  +		[
          161  +			{ "id": "5001", "type": "None" },
          162  +			{ "id": "5002", "type": "Glazed" },
          163  +			{ "id": "5005", "type": "Sugar" },
          164  +			{ "id": "5007", "type": "Powdered Sugar" },
          165  +			{ "id": "5006", "type": "Chocolate with Sprinkles" },
          166  +			{ "id": "5003", "type": "Chocolate" },
          167  +			{ "id": "5004", "type": "Maple" }
          168  +		]
          169  +   }','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html');
          170  +   INSERT INTO j2(id,json,src)
          171  +   VALUES(3,'[
          172  +	{
          173  +		"id": "0001",
          174  +		"type": "donut",
          175  +		"name": "Cake",
          176  +		"ppu": 0.55,
          177  +		"batters":
          178  +			{
          179  +				"batter":
          180  +					[
          181  +						{ "id": "1001", "type": "Regular" },
          182  +						{ "id": "1002", "type": "Chocolate" },
          183  +						{ "id": "1003", "type": "Blueberry" },
          184  +						{ "id": "1004", "type": "Devil''s Food" }
          185  +					]
          186  +			},
          187  +		"topping":
          188  +			[
          189  +				{ "id": "5001", "type": "None" },
          190  +				{ "id": "5002", "type": "Glazed" },
          191  +				{ "id": "5005", "type": "Sugar" },
          192  +				{ "id": "5007", "type": "Powdered Sugar" },
          193  +				{ "id": "5006", "type": "Chocolate with Sprinkles" },
          194  +				{ "id": "5003", "type": "Chocolate" },
          195  +				{ "id": "5004", "type": "Maple" }
          196  +			]
          197  +	},
          198  +	{
          199  +		"id": "0002",
          200  +		"type": "donut",
          201  +		"name": "Raised",
          202  +		"ppu": 0.55,
          203  +		"batters":
          204  +			{
          205  +				"batter":
          206  +					[
          207  +						{ "id": "1001", "type": "Regular" }
          208  +					]
          209  +			},
          210  +		"topping":
          211  +			[
          212  +				{ "id": "5001", "type": "None" },
          213  +				{ "id": "5002", "type": "Glazed" },
          214  +				{ "id": "5005", "type": "Sugar" },
          215  +				{ "id": "5003", "type": "Chocolate" },
          216  +				{ "id": "5004", "type": "Maple" }
          217  +			]
          218  +	},
          219  +	{
          220  +		"id": "0003",
          221  +		"type": "donut",
          222  +		"name": "Old Fashioned",
          223  +		"ppu": 0.55,
          224  +		"batters":
          225  +			{
          226  +				"batter":
          227  +					[
          228  +						{ "id": "1001", "type": "Regular" },
          229  +						{ "id": "1002", "type": "Chocolate" }
          230  +					]
          231  +			},
          232  +		"topping":
          233  +			[
          234  +				{ "id": "5001", "type": "None" },
          235  +				{ "id": "5002", "type": "Glazed" },
          236  +				{ "id": "5003", "type": "Chocolate" },
          237  +				{ "id": "5004", "type": "Maple" }
          238  +			]
          239  +	}
          240  +   ]','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html');
          241  +   SELECT count(*) FROM j2;
          242  +} {3}
          243  +
          244  +do_execsql_test json-5.2 {
          245  +  SELECT id, json_valid(json), json_type(json), '|' FROM j2 ORDER BY id;
          246  +} {1 1 object | 2 1 object | 3 1 array |}
          247  +
          248  +ifcapable !vtab {
          249  +  finish_test
          250  +  return
          251  +}
          252  +
          253  +# fullkey is always the same as path+key (with appropriate formatting)
          254  +#
          255  +do_execsql_test json-5.3 {
          256  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          257  +    FROM j2, json_tree(j2.json) AS jx
          258  +   WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
          259  +                                ELSE '.'||key END);
          260  +} {}
          261  +do_execsql_test json-5.4 {
          262  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          263  +    FROM j2, json_each(j2.json) AS jx
          264  +   WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
          265  +                                ELSE '.'||key END);
          266  +} {}
          267  +
          268  +
          269  +# Verify that the json_each.json and json_tree.json output is always the
          270  +# same as input.
          271  +#
          272  +do_execsql_test json-5.5 {
          273  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          274  +    FROM j2, json_each(j2.json) AS jx
          275  +   WHERE jx.json<>j2.json;
          276  +} {}
          277  +do_execsql_test json-5.6 {
          278  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          279  +    FROM j2, json_tree(j2.json) AS jx
          280  +   WHERE jx.json<>j2.json;
          281  +} {}
          282  +do_execsql_test json-5.7 {
          283  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          284  +    FROM j2, json_each(j2.json) AS jx
          285  +   WHERE jx.value<>jx.atom AND type NOT IN ('array','object');
          286  +} {}
          287  +do_execsql_test json-5.8 {
          288  +  SELECT j2.rowid, jx.rowid, fullkey, path, key
          289  +    FROM j2, json_tree(j2.json) AS jx
          290  +   WHERE jx.value<>jx.atom AND type NOT IN ('array','object');
          291  +} {}
          292  +
          293  +
   115    294   
   116    295   finish_test