-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished implementation of "piqi getopt" command; added tests and exa…
…mples.
- Loading branch information
Showing
7 changed files
with
228 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
# | ||
# pretty-printing args as Piq AST | ||
# | ||
|
||
piqi getopt # empty input | ||
piqi getopt -- # empty input | ||
|
||
piqi getopt -- foo | ||
piqi getopt -- 10 -20 30.0 -0.inf 0.nan '"foo\r"' '"\xff"' -fum [ -foo bar [] ] -baz | ||
|
||
|
||
# | ||
# converting args to Piq objects | ||
# | ||
# NOTE: converting to encodings other than Piq (controlled by -t parameter) is | ||
# tested as a part of "piqi convert" testing as they share the same | ||
# functionality | ||
# | ||
|
||
# built-in types | ||
|
||
piqi getopt --piqtype bool -- true | ||
piqi getopt --piqtype int -- -10 | ||
piqi getopt --piqtype float -- -0.inf | ||
|
||
piqi getopt --piqtype string -- foo # parsing words as strings | ||
piqi getopt --piqtype string -- foo\ bar | ||
piqi getopt --piqtype string -- '"\tfoo\x20\u0045"' | ||
piqi getopt --piqtype string -- "привет" | ||
piqi getopt --piqtype binary -- '"\x00ab\tcd\xff\xfe"' | ||
|
||
piqi getopt --piqtype piq-word -- foo-bar | ||
piqi getopt --piqtype piq-any -- 10 -20 30.0 -0.inf 0.nan '"foo\r"' '"\xff"' -fum [ -foo bar [] ] -baz | ||
#NOTE: piq-text is not supported | ||
|
||
# complex types | ||
|
||
piqi getopt --piqtype complex/t -- [ .re 0 .im 0 ] | ||
piqi getopt --piqtype complex/t -- .re 0 .im 0 | ||
piqi getopt --piqtype complex/t -- -re 0 -im 0 | ||
piqi getopt --piqtype complex/t -- 0 0 | ||
piqi getopt --piqtype complex/foo -- [] | ||
piqi getopt --piqtype complex/foo -- [ ] | ||
piqi getopt --piqtype complex/foo --add-defaults -- [ ] | ||
|
||
piqi getopt --piqtype def/r -- -i 0 -flag | ||
piqi getopt --piqtype def/r -- -i 0 -flag | ||
piqi getopt --piqtype def/r -- -i 0 -flag | ||
|
||
piqi getopt --piqtype def/int-list -- [] | ||
piqi getopt --piqtype def/int-list -- [ 1 2 3 4 5 ] | ||
piqi getopt --piqtype def/int-list -- 1 2 3 4 5 | ||
piqi getopt --piqtype def/int-list-list -- [ [] [ 1 2 3 ] ] | ||
piqi getopt --piqtype def/int-list-list -- [] [ 1 2 3 ] | ||
|
||
piqi getopt --piqtype record-variant-list/r -- -a 0 -b 1 | ||
piqi getopt --piqtype record-variant-list/l -- -a 0 -b 1 | ||
piqi getopt --piqtype record-variant-list/v -- -a 0 | ||
piqi getopt --piqtype record-variant-list/v -- -b 1 | ||
|
||
piqi getopt --piqtype person/person -- \ | ||
-name "J. Random Hacker" \ | ||
-id 0 \ | ||
-email "[email protected]" \ | ||
-phone [ -number "(111) 123 45 67" ] \ | ||
-phone [ \ | ||
-number "(222) 123 45 67" \ | ||
-mobile \ | ||
] \ | ||
-phone [ \ | ||
-number "(333) 123 45 67" \ | ||
-work \ | ||
] | ||
|
||
piqi getopt --piqtype person/person -- \ | ||
.name "Joe User" \ | ||
.id 1 \ | ||
.phone [ "(444) 123 45 67" ] \ | ||
.phone [ "(555) 123 45 67" .work ] | ||
|
||
|
||
piqi getopt --piqtype function/bar-input -- [ 10 ] | ||
piqi getopt --piqtype function/bar-output -- 1 | ||
piqi getopt --piqtype function/bar-error -- 100.0 | ||
|
||
piqi getopt --piqtype function/baz-input -- [] | ||
piqi getopt --piqtype function/baz-input --add-defaults -- [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.