Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 08ec4f0 commit 45afbe6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 53 deletions.
6 changes: 3 additions & 3 deletions dev/snippets.jq
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def mp4_box:

def flac_dump:
[ "fLaC"
, first(.. | select(._format == "flac_metadatablock"))
, (.. | select(._format == "flac_frame"))
, first(.. | select(format == "flac_metadatablock"))
, (.. | select(format == "flac_frame"))
] | tobits;

def urldecode:
Expand Down Expand Up @@ -37,7 +37,7 @@ def radix62sp: radix(62; "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR
"V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61
});

# "01:09:55.76" -> 4195.76 ->
# "01:09:55.76" -> 4195.76
# 4195.76 -> "01:09:55.76"
def duration:
def lpad($s; $w): ($s * ($w+1-length))[1:] + .;
Expand Down
2 changes: 1 addition & 1 deletion format/id3/testdata/apic.fqtest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ffmpeg -f lavfi -i anullsrc=d=10ms -f lavfi -i testsrc=s=4x4:r=1:d=1 -map 0:0 -map 1:0 -f mp3 test.mp3
# fq test.mp3 '.. | select(._format == "id3v2")?._bytes' > apic
# fq test.mp3 '.. | select(format == "id3v2")._bytes' > apic
/apic:
$ fq -d id3v2 verbose /apic
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} /apic (id3v2) 0x0-0xb3.7 (180)
Expand Down
5 changes: 0 additions & 5 deletions pkg/fqtest/fqtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ func parseTestCases(s string) *testCase {
replDepth--
}

if replDepth == 0 {
te.parts = append(te.parts, currentTestRun)
currentTestRun = nil
}

default:
panic(fmt.Sprintf("%d: unexpected section %q %q", section.LineNr, n, v))
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/interp/funcs.jq
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
def format: ._format? // null;

def format:
if type == "object" then ._format
else ._format? // null
end;

# integer division
# inspried by https://github.com/itchyny/gojq/issues/63#issuecomment-765066351
Expand Down Expand Up @@ -224,7 +228,7 @@ def radix($base; $to_table; $from_table):

def radix2: radix(2; "01"; {"0": 0, "1": 1});
def radix8: radix(8; "01234567"; {"0": 0, "1": 1, "2": 2, "3": 3,"4": 4, "5": 5, "6": 6, "7": 7});
def radix16:radix(16; "0123456789abcdef"; {
def radix16: radix(16; "0123456789abcdef"; {
"0": 0, "1": 1, "2": 2, "3": 3,"4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
"a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15
});
Expand Down Expand Up @@ -263,8 +267,7 @@ def radix64: radix(64; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123
"+": 62, "/": 63
});

# like iprint
def i:
def iprint:
{
bin: "0b\(radix2)",
oct: "0o\(radix8)",
Expand Down
56 changes: 16 additions & 40 deletions pkg/interp/testdata/basic.fqtest
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
# ffmpeg -f lavfi -i sine -t 10ms test.mp3
/test.mp3:
$ fq -d mp3 '.headers[0].magic == "ID3"' /test.mp3
$ fq -i . /test.mp3
mp3> .headers[0].magic == "ID3"
true
$ fq -d mp3 '.headers[0].version == 4' /test.mp3
mp3> .headers[0].version == 4
true
$ fq -d mp3 '.frames[0].header.protection == true' /test.mp3
mp3> .frames[0].header.protection == true
true
$ fq -d mp3 '.headers[0].flags + {}' /test.mp3
mp3> .headers[0].flags + {}
{
"experimental_indicator": false,
"extended_header": false,
"unsynchronisation": false,
"unused": 0
}
$ fq -d mp3 '._unknown' /test.mp3
mp3> ._unknown
false
$ fq -d mp3 '._format' /test.mp3
mp3> format
"mp3"
$ fq -d mp3 '.headers[0].magic._format' /test.mp3
mp3> .headers[0].magic | format
null
$ fq -d raw '._bytes | tostring'
"abc\n"
mp3> ._format
"mp3"
mp3> .headers[0].magic._format
null
mp3> ^D
$ fq -d raw .
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} - (raw)
0x0|61 62 63 0a| |abc.| | unknown0: 6162630a
stdin:
abc
$ fq -n "{a: 123, b: []} | debug"
{
"a": 123,
"b": []
}
stderr:
["DEBUG",{"a":123,"b":[]}]
$ fq -n options
{
"addrbase": 16,
"bitsformat": "snippet",
"bytecolors": "0-0xff=brightwhite,0=brightblack,32-126:9-13=white",
"color": false,
"colors": "array=white,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=white,null=brightblack,number=cyan,object=white,objectkey=brightblue,string=green,true=yellow,value=white",
"compact": false,
"decode_progress": false,
"depth": 0,
"displaybytes": 16,
"expr_file": null,
"include_path": null,
"join_string": "\n",
"linebytes": 16,
"null_input": true,
"raw_output": false,
"raw_string": false,
"repl": false,
"sizebase": 10,
"slurp": false,
"unicode": false,
"verbose": false
}
15 changes: 15 additions & 0 deletions pkg/interp/testdata/debug.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$ fq -i
null> {a: 123, b: []} | debug
{
"a": 123,
"b": []
}
null> {a: 123, b: []} | debug({a})
{
"a": 123,
"b": []
}
null> ^D
stderr:
["DEBUG",{"a":123,"b":[]}]
["DEBUG",{"a":123}]
24 changes: 24 additions & 0 deletions pkg/interp/testdata/options.fqtest
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
$ fq -n options
{
"addrbase": 16,
"bitsformat": "snippet",
"bytecolors": "0-0xff=brightwhite,0=brightblack,32-126:9-13=white",
"color": false,
"colors": "array=white,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=white,null=brightblack,number=cyan,object=white,objectkey=brightblue,string=green,true=yellow,value=white",
"compact": false,
"decode_progress": false,
"depth": 0,
"displaybytes": 16,
"expr_file": null,
"include_path": null,
"join_string": "\n",
"linebytes": 16,
"null_input": true,
"raw_output": false,
"raw_string": false,
"repl": false,
"sizebase": 10,
"slurp": false,
"unicode": false,
"verbose": false
}
$ fq -o addrbase=10 -n options.addrbase
10
$ fq -o addrbase=true -n options.addrbase
Expand Down

0 comments on commit 45afbe6

Please sign in to comment.