1
1
mirror of https://github.com/wader/fq.git synced 2024-12-28 08:02:28 +03:00
fq/pkg/interp/testdata/value_array.fqtest
Mattias Wadman 518f6af4a8 gojq: Rebase fq fork
Upstream changes:
Many performance improvements
Error message improvments
Lots of refactoring

Most of the JQValue interface changes in gojq fork had to be reworked but
resultet in a much nicer and cleaner changeset.

fq changes:
Assignment to JQValue (like a decode value) now shallowly converts the value into
a jq value before assigning. Was a bit hacky as it was and this makes JQValue
behave more like real jq values. This also fixes some advanced indexing issues.

Actual custom path updates will be something for the future.
2022-04-11 19:23:15 +02:00

895 lines
22 KiB
Plaintext

$ fq -i -d mp3 . /test.mp3
mp3> .headers | ., tovalue, type, length?
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.headers[0:1]:
0x00|49 44 33 04 00 00 00 00 00 23 54 53 53 45 00 00|ID3......#TSSE..| [0]{}: (id3v2)
* |until 0x2c.7 (45) | |
[
{
"flags": {
"experimental_indicator": false,
"extended_header": false,
"unsynchronisation": false,
"unused": 0
},
"frames": [
{
"flags": {
"compression": false,
"data_length_indicator": false,
"encryption": false,
"file_alter_preservation": false,
"grouping_identity": false,
"read_only": false,
"tag_alter_preservation": false,
"unsync": false,
"unused0": 0,
"unused1": 0,
"unused2": 0
},
"id": "TSSE",
"size": 15,
"text": "Lavf58.45.100",
"text_encoding": "utf8"
}
],
"magic": "ID3",
"padding": "<10>AAAAAAAAAAAAAA==",
"revision": 0,
"size": 35,
"version": 4
}
]
"array"
1
mp3> .headers[0] | ., type, length?
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.headers[0]{}: (id3v2)
0x00|49 44 33 |ID3 | magic: "ID3" (valid)
0x00| 04 | . | version: 4
0x00| 00 | . | revision: 0
0x00| 00 | . | flags{}:
0x00| 00 00 00 23 | ...# | size: 35
0x00| 54 53 53 45 00 00| TSSE..| frames[0:1]:
0x10|00 0f 00 00 03 4c 61 76 66 35 38 2e 34 35 2e 31|.....Lavf58.45.1|
0x20|30 30 00 |00. |
0x20| 00 00 00 00 00 00 00 00 00 00 | .......... | padding: raw bits (all zero)
"object"
7
mp3> .headers[-1000] | ., type, length?
null
"null"
0
mp3> .headers[1000] | ., type, length?
null
"null"
0
mp3> .headers[1:3] | ., type, length?
[]
"array"
0
mp3> .headers[0:-1] | ., type, length?
[]
"array"
0
mp3> .headers[-1000:2000] | ., type, length?
[
{
"flags": {
"experimental_indicator": false,
"extended_header": false,
"unsynchronisation": false,
"unused": 0
},
"frames": [
{
"flags": {
"compression": false,
"data_length_indicator": false,
"encryption": false,
"file_alter_preservation": false,
"grouping_identity": false,
"read_only": false,
"tag_alter_preservation": false,
"unsync": false,
"unused0": 0,
"unused1": 0,
"unused2": 0
},
"id": "TSSE",
"size": 15,
"text": "Lavf58.45.100",
"text_encoding": "utf8"
}
],
"magic": "ID3",
"padding": "<10>AAAAAAAAAAAAAA==",
"revision": 0,
"size": 35,
"version": 4
}
]
"array"
1
mp3> .headers["test"] | ., type, length?
error: expected an object with key "test" but got: array
mp3> [.headers[]] | type, length?
"array"
1
mp3> .headers | keys
[
0
]
mp3> .headers | has("a")
error: cannot check whether array has a key: a
mp3> .headers | has(0)
true
mp3> .headers | type
"array"
mp3> .headers | tonumber
error: tonumber cannot be applied to: array
mp3> .headers | tostring
error: tostring cannot be applied to: array
mp3> .headers + ""
error: cannot add: array ([{"flags":{"experimental_ ...]) and string ("")
mp3> .headers + 1
error: cannot add: array ([{"flags":{"experimental_ ...]) and number (1)
mp3> .headers._start | ., type, length?
0
"number"
0
mp3> .headers._stop | ., type, length?
360
"number"
360
mp3> .headers._len | ., type, length?
360
"number"
360
mp3> .headers._name | ., type, length?
"headers"
"string"
7
mp3> .headers._sym | ., type, length?
null
"null"
0
mp3> .headers._description | ., type, length?
null
"null"
0
mp3> .headers._path | ., type, length?
[
"headers"
]
"array"
1
mp3> .headers._bits | ., type, length?
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x00|49 44 33 04 00 00 00 00 00 23 54 53 53 45 00 00|ID3......#TSSE..|.: raw bits 0x0-0x2c.7 (45)
* |until 0x2c.7 (45) | |
"binary"
360
mp3>
mp3> .headers._bytes | ., type, length?
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x00|49 44 33 04 00 00 00 00 00 23 54 53 53 45 00 00|ID3......#TSSE..|.: raw bits 0x0-0x2c.7 (45)
* |until 0x2c.7 (45) | |
"binary"
45
mp3>
mp3> .headers._error | ., type, length?
null
"null"
0
mp3> .headers._unknown | ., type, length?
false
"boolean"
mp3> .headers.a = 1
error: expected an object but got: array ([{"flags":{"experimental_ ...])
mp3> .headers[0] = 1
{
"footers": [],
"frames": [
{
"crc_calculated": "827a",
"header": {
"bitrate": 56000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 0,
"padding": "not_padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"padding": "<5>AAAAAAA=",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 0,
"part2_3_length": 0,
"preflag": 0,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
},
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 0,
"part2_3_length": 0,
"preflag": 0,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
}
],
"main_data_end": 0,
"private_bits": 0,
"share0": 0
},
"xing": {
"bytes": 599,
"frames": 2,
"header": "Info",
"lame_extension": {
"abr_vbr": 0,
"audiophile_replay_gain": 0,
"encoder": "Lavc58.91",
"encoder_delay": 576,
"encoder_padding": 1287,
"lame_ath_type": 0,
"lame_flags": 0,
"length": 599,
"lowpass_filter": 0,
"misc": 0,
"mp3_gain": 0,
"music_crc": 25328,
"preset": 0,
"radio_replay_gain": 0,
"replay_gain_peak": 0,
"tag_crc": 23093,
"tag_revision": 0,
"vbr_method": 0
},
"present_flags": {
"bytes": true,
"frames": true,
"quality": true,
"toc": true,
"unused": 0
},
"quality": 0,
"toc": [
0,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255
]
}
},
{
"crc_calculated": "e5b0",
"data": "<187>B6rDjjOF02TxocEIHFgfXh8YHEYEHonlsy5aD6g7E2vw+GBQFAQDAoJEDE5o0aNsH3iAEAQxOD/BB050+c5fznL+7p93Lg+D4Ph8EAxKAMH9IAH///555554T7EPKQdc5TdRYNYihmqWGn6jVTNuL+Em0eAKJCYbPQRwVHtKrRk2Hogmi3/vFJwLDWJ//++4IUY5R/oJnyoaCgV9HgUESINnfuTyoCETQkEv/+OQSYPWtQkEQMCZSqCIEQ==",
"header": {
"bitrate": 64000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 1,
"padding": "not_padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"other_data": "<0>",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 33,
"block_type": "start block",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 151,
"part2_3_length": 651,
"preflag": 0,
"scalefac_compress": 2,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 25,
"table_select1": 9
}
]
},
{
"channels": [
{
"big_values": 77,
"block_type": "3 short windows",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 172,
"part2_3_length": 769,
"preflag": 0,
"scalefac_compress": 9,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 24,
"table_select1": 8
}
]
}
],
"main_data_end": 0,
"private_bits": 0,
"share0": 0
}
},
{
"crc_calculated": "61fd",
"data": "<178>EUs2SgiDWMkg1ClSmMjI+ROAQCS8kSNCUFYNGBEDQd6wVWCsRHiwdgr6P4lOlXKBqDUqdWdiL/BXlj3Ev//xEkxBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg==",
"header": {
"bitrate": 64000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 1,
"padding": "padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"other_data": "<9>qqqqqqqqqqqq",
"padding_byte": "<1>qg==",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 28,
"block_type": "end",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 148,
"part2_3_length": 581,
"preflag": 0,
"scalefac_compress": 9,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 12,
"table_select1": 6
}
]
},
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 210,
"part2_3_length": 0,
"preflag": 1,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
}
],
"main_data_end": 9,
"private_bits": 0,
"share0": 15
}
}
],
"headers": [
1
]
}
mp3> .headers.a |= empty
error: expected an object with key "a" but got: array
mp3> .headers[0] |= empty
{
"footers": [],
"frames": [
{
"crc_calculated": "827a",
"header": {
"bitrate": 56000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 0,
"padding": "not_padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"padding": "<5>AAAAAAA=",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 0,
"part2_3_length": 0,
"preflag": 0,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
},
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 0,
"part2_3_length": 0,
"preflag": 0,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
}
],
"main_data_end": 0,
"private_bits": 0,
"share0": 0
},
"xing": {
"bytes": 599,
"frames": 2,
"header": "Info",
"lame_extension": {
"abr_vbr": 0,
"audiophile_replay_gain": 0,
"encoder": "Lavc58.91",
"encoder_delay": 576,
"encoder_padding": 1287,
"lame_ath_type": 0,
"lame_flags": 0,
"length": 599,
"lowpass_filter": 0,
"misc": 0,
"mp3_gain": 0,
"music_crc": 25328,
"preset": 0,
"radio_replay_gain": 0,
"replay_gain_peak": 0,
"tag_crc": 23093,
"tag_revision": 0,
"vbr_method": 0
},
"present_flags": {
"bytes": true,
"frames": true,
"quality": true,
"toc": true,
"unused": 0
},
"quality": 0,
"toc": [
0,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
166,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255
]
}
},
{
"crc_calculated": "e5b0",
"data": "<187>B6rDjjOF02TxocEIHFgfXh8YHEYEHonlsy5aD6g7E2vw+GBQFAQDAoJEDE5o0aNsH3iAEAQxOD/BB050+c5fznL+7p93Lg+D4Ph8EAxKAMH9IAH///555554T7EPKQdc5TdRYNYihmqWGn6jVTNuL+Em0eAKJCYbPQRwVHtKrRk2Hogmi3/vFJwLDWJ//++4IUY5R/oJnyoaCgV9HgUESINnfuTyoCETQkEv/+OQSYPWtQkEQMCZSqCIEQ==",
"header": {
"bitrate": 64000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 1,
"padding": "not_padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"other_data": "<0>",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 33,
"block_type": "start block",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 151,
"part2_3_length": 651,
"preflag": 0,
"scalefac_compress": 2,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 25,
"table_select1": 9
}
]
},
{
"channels": [
{
"big_values": 77,
"block_type": "3 short windows",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 172,
"part2_3_length": 769,
"preflag": 0,
"scalefac_compress": 9,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 24,
"table_select1": 8
}
]
}
],
"main_data_end": 0,
"private_bits": 0,
"share0": 0
}
},
{
"crc_calculated": "61fd",
"data": "<178>EUs2SgiDWMkg1ClSmMjI+ROAQCS8kSNCUFYNGBEDQd6wVWCsRHiwdgr6P4lOlXKBqDUqdWdiL/BXlj3Ev//xEkxBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg==",
"header": {
"bitrate": 64000,
"channel_mode": "none",
"channels": "mono",
"copyright": 0,
"emphasis": "none",
"layer": 3,
"mpeg_version": "1",
"original": 1,
"padding": "padded",
"private": 0,
"protection_absent": true,
"sample_count": 1152,
"sample_rate": 44100,
"sync": 2047
},
"other_data": "<9>qqqqqqqqqqqq",
"padding_byte": "<1>qg==",
"side_info": {
"granules": [
{
"channels": [
{
"big_values": 28,
"block_type": "end",
"blocksplit_flag": 1,
"count1table_select": 0,
"global_gain": 148,
"part2_3_length": 581,
"preflag": 0,
"scalefac_compress": 9,
"scalefac_scale": 0,
"subblock_gain0": 0,
"subblock_gain1": 0,
"subblock_gain2": 0,
"switch_point": 0,
"table_select0": 12,
"table_select1": 6
}
]
},
{
"channels": [
{
"big_values": 0,
"blocksplit_flag": 0,
"count1table_select": 0,
"global_gain": 210,
"part2_3_length": 0,
"preflag": 1,
"region_address1": 0,
"region_address2": 0,
"scalefac_compress": 0,
"scalefac_scale": 0,
"table_select0": 0,
"table_select1": 0,
"table_select2": 0
}
]
}
],
"main_data_end": 9,
"private_bits": 0,
"share0": 15
}
}
],
"headers": []
}
mp3> .headers | setpath(["a"]; 1)
error: expected an object but got: array ([{"flags":{"experimental_ ...])
mp3> .headers | setpath([0]; 1)
[
1
]
mp3> .headers | delpaths([["a"]])
error: expected an object but got: array ([{"flags":{"experimental_ ...])
mp3> .headers | delpaths([[0]])
[]
mp3> ^D