| 1 | #cxx . . $ `<file>/t/cli.cc`/include <opustags.h>cxx . . $ `<file>/src/opustags.h`/ |
| 2 | #include "tap.h"cxx . . $ `<file>/t/tap.h`/ |
| 3 | |
| 4 | #include <string.h> |
| 5 | |
| 6 | static otcxx . . $ ot/::statuscxx . . $ ot/status# read_commentscxx . . $ read_comments(4b8bc7dac536a016).(FILE* input, stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::u8stringcxx . . $ std/u8string#>& comments, bool raw) |
| 7 | { |
| 8 | otcxx . . $ ot/::optionscxx . . $ ot/options# opt; |
| 9 | opt.rawcxx . . $ ot/options#raw. = raw; |
| 10 | try { |
| 11 | comments =cxx . . $ std/__cxx11/list#`operator=`(926e4d17a59d25e2). otcxx . . $ ot/::read_commentscxx . . $ ot/read_comments(40038bce797cca1f).(input, opt); |
| 12 | } catch (const otcxx . . $ ot/::statuscxx . . $ ot/status#& rc) { |
| 13 | return rc; |
| 14 | } |
| 15 | return otcxx . . $ ot/status#status(570d951ce3a7f975).::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.; |
| 16 | } |
| 17 | |
| 18 | void check_read_commentscxx . . $ check_read_comments(49f6e7a06ebc5aa8).() |
| 19 | { |
| 20 | stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::u8stringcxx . . $ std/u8string#> commentscxx . . $ std/__cxx11/list#list(49f6e7a06ebc5aa8).; |
| 21 | otcxx . . $ ot/::statuscxx . . $ ot/status# rccxx . . $ ot/status#status(570d951ce3a7f975).; |
| 22 | { |
| 23 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "TITLE=a b c\n\nARTIST=X\nArtist=Y\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 24 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 25 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, false); |
| 26 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.) |
| 27 | throw failurecxx . . $ tap/failure#("could not read comments"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 28 | auto&& expected = {u8"TITLE=a b c", u8"ARTIST=X", u8"Artist=Y"}; |
| 29 | if (!stdcxx . . $ std/::equalcxx . . $ std/equal(51c87e3d44d61bd6).(comments.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), comments.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(), expected.begincxx . . $ std/initializer_list#begin(8e614c7de0b1573e).(), expected.endcxx . . $ std/initializer_list#end(8e614c7de0b1573e).())) |
| 30 | throw failurecxx . . $ tap/failure#("parsed user comments did not match expectations"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 31 | } |
| 32 | { |
| 33 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "CORRUPTED=\xFF\xFF\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 34 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 35 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, false); |
| 36 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::badly_encodedcxx . . $ ot/st#badly_encoded.) |
| 37 | throw failurecxx . . $ tap/failure#("did not get the expected error reading corrupted data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 38 | } |
| 39 | { |
| 40 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "RAW=\xFF\xFF\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 41 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 42 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, true); |
| 43 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.) |
| 44 | throw failurecxx . . $ tap/failure#("could not read comments"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 45 | if (comments.frontcxx . . $ std/__cxx11/list#front(d5f1ba0ed5a2655c).() != (char8_t*) "RAW=\xFF\xFF") |
| 46 | throw failurecxx . . $ tap/failure#("parsed user comments did not match expectations"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 47 | } |
| 48 | { |
| 49 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "MULTILINE=First\n\tSecond\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 50 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 51 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, true); |
| 52 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.) |
| 53 | throw failurecxx . . $ tap/failure#("could not read comments"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 54 | if (comments.frontcxx . . $ std/__cxx11/list#front(d5f1ba0ed5a2655c).() != u8"MULTILINE=First\nSecond") |
| 55 | throw failurecxx . . $ tap/failure#("parsed user comments did not match expectations"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 56 | } |
| 57 | { |
| 58 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "MALFORMED\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 59 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 60 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, false); |
| 61 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::errorcxx . . $ ot/st#error.) |
| 62 | throw failurecxx . . $ tap/failure#("did not get the expected error reading malformed comments"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 63 | } |
| 64 | { |
| 65 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "\tBad"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 66 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 67 | rc =cxx . . $ ot/status#`operator=`(a0ede868b080ffee). read_commentscxx . . $ read_comments(4b8bc7dac536a016).(input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), comments, true); |
| 68 | if (rc != otcxx . . $ ot/::stcxx . . $ ot/st#::errorcxx . . $ ot/st#error.) |
| 69 | throw failurecxx . . $ tap/failure#("did not get the expected error reading bad continuation line"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Wrap #ot::parse_options with a higher-level interface much more convenient for testing. |
| 75 | * In practice, the argc/argv combo are enough though for the current state of opustags. |
| 76 | */ |
| 77 | static otcxx . . $ ot/::statuscxx . . $ ot/status# parse_optionscxx . . $ parse_options(f7b722e81092e1ea).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*>& args, otcxx . . $ ot/::optionscxx . . $ ot/options#& opt, FILE *comments) |
| 78 | { |
| 79 | int argc = args.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 80 | char* argv[argc]; |
| 81 | for (int i = 0; i < argc; ++i) |
| 82 | argv[i] = strdup(args[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]); |
| 83 | otcxx . . $ ot/::statuscxx . . $ ot/status# rc = otcxx . . $ ot/status#status(570d951ce3a7f975).::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.; |
| 84 | try { |
| 85 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). otcxx . . $ ot/::parse_optionscxx . . $ ot/parse_options(be20433a3686cf7a).(argc, argv, comments); |
| 86 | } catch (const otcxx . . $ ot/::statuscxx . . $ ot/status#& e) { |
| 87 | rc =cxx . . $ ot/status#`operator=`(ede20b08b8729810). e; |
| 88 | } |
| 89 | for (int i = 0; i < argc; ++i) |
| 90 | free(argv[i]); |
| 91 | return rc; |
| 92 | } |
| 93 | |
| 94 | void check_good_argumentscxx . . $ check_good_arguments(49f6e7a06ebc5aa8).() |
| 95 | { |
| 96 | auto parse = [](stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*> args) { |
| 97 | otcxx . . $ ot/::optionscxx . . $ ot/options# opt; |
| 98 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "N=1\n"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 99 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 100 | otcxx . . $ ot/::statuscxx . . $ ot/status# rc = parse_optionscxx . . $ parse_options(f7b722e81092e1ea).(args, opt, input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()); |
| 101 | if (rc.codecxx . . $ ot/status#code. != otcxx . . $ ot/::stcxx . . $ ot/st#::okcxx . . $ ot/st#ok.) |
| 102 | throw failurecxx . . $ tap/failure#("unexpected option parsing error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 103 | return opt; |
| 104 | }; |
| 105 | |
| 106 | otcxx . . $ ot/::optionscxx . . $ ot/options# opt; |
| 107 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--help", "x", "-o", "y"}); |
| 108 | if (!opt.print_helpcxx . . $ ot/options#print_help.) |
| 109 | throw failurecxx . . $ tap/failure#("did not catch --help"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 110 | |
| 111 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "x", "--output", "y", "-D", "-s", "X=Y Z", "-d", "a=b"}); |
| 112 | if (opt.paths_incxx . . $ ot/options#paths_in..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != 1 || opt.paths_incxx . . $ ot/options#paths_in..frontcxx . . $ std/vector#front(6baabfa6fc7b3a8e).() != "x" || !opt.path_outcxx . . $ ot/options#path_out. || |
| 113 | opt.path_outcxx . . $ ot/options#path_out. !=cxx . . $ std/`operator!=`(cd853fd68ea5eee9). "y" || !opt.delete_allcxx . . $ ot/options#delete_all. || opt.overwritecxx . . $ ot/options#overwrite. || opt.to_deletecxx . . $ ot/options#to_delete..sizecxx . . $ std/__cxx11/list#size(c9b1e749b64d5edc).() != 2 || |
| 114 | opt.to_deletecxx . . $ ot/options#to_delete..frontcxx . . $ std/__cxx11/list#front(d5f1ba0ed5a2655c).() != u8"X" || *cxx . . $ std/_List_iterator#`operator*`(d426bc7b625886b7).stdcxx . . $ std/::nextcxx . . $ std/next(31d62cd24490f169).(opt.to_deletecxx . . $ ot/options#to_delete..begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).()) != u8"a=b" || |
| 115 | opt.to_addcxx . . $ ot/options#to_add. != stdcxx . . $ std/__cxx11/list#list(9619226211e5a241).::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::u8stringcxx . . $ std/u8string#>{ u8"X=Y Z" }) |
| 116 | throw failurecxx . . $ tap/failure#("unexpected option parsing result for case #1"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 117 | |
| 118 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-S", "x", "-S", "-a", "x=y z", "-i"}); |
| 119 | if (opt.paths_incxx . . $ ot/options#paths_in..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != 1 || opt.paths_incxx . . $ ot/options#paths_in..frontcxx . . $ std/vector#front(6baabfa6fc7b3a8e).() != "x" || opt.path_outcxx . . $ ot/options#path_out. || |
| 120 | !opt.overwritecxx . . $ ot/options#overwrite. || opt.to_deletecxx . . $ ot/options#to_delete..sizecxx . . $ std/__cxx11/list#size(c9b1e749b64d5edc).() != 0 || |
| 121 | opt.to_addcxx . . $ ot/options#to_add. != stdcxx . . $ std/__cxx11/list#list(9619226211e5a241).::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::u8stringcxx . . $ std/u8string#>{ u8"N=1", u8"x=y z" }) |
| 122 | throw failurecxx . . $ tap/failure#("unexpected option parsing result for case #2"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 123 | |
| 124 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-i", "x", "y", "z"}); |
| 125 | if (opt.paths_incxx . . $ ot/options#paths_in..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != 3 || opt.paths_incxx . . $ ot/options#paths_in.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0] != "x" || opt.paths_incxx . . $ ot/options#paths_in.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1] != "y" || |
| 126 | opt.paths_incxx . . $ ot/options#paths_in.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2] != "z" || !opt.overwritecxx . . $ ot/options#overwrite. || !opt.in_placecxx . . $ ot/options#in_place.) |
| 127 | throw failurecxx . . $ tap/failure#("unexpected option parsing result for case #3"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 128 | |
| 129 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-ie", "x"}); |
| 130 | if (opt.paths_incxx . . $ ot/options#paths_in..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != 1 || opt.paths_incxx . . $ ot/options#paths_in.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0] != "x" || |
| 131 | !opt.edit_interactivelycxx . . $ ot/options#edit_interactively. || !opt.overwritecxx . . $ ot/options#overwrite. || !opt.in_placecxx . . $ ot/options#in_place.) |
| 132 | throw failurecxx . . $ tap/failure#("unexpected option parsing result for case #4"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 133 | |
| 134 | opt =cxx . . $ ot/options#`operator=`(80e0391707d06066). parse(cxx . . $ check_good_arguments(49f6e7a06ebc5aa8).$anonymous_type_0#`operator()`(1088c258ebc502d8).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-a", "X=\xFF", "--raw", "x"}); |
| 135 | if (!opt.rawcxx . . $ ot/options#raw. || opt.to_addcxx . . $ ot/options#to_add..frontcxx . . $ std/__cxx11/list#front(d5f1ba0ed5a2655c).() != u8"X=\xFF") |
| 136 | throw failurecxx . . $ tap/failure#("--raw did not disable transcoding"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 137 | } |
| 138 | |
| 139 | void check_bad_argumentscxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).() |
| 140 | { |
| 141 | auto error_code_case = [](stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*> args, const char* message, otcxx . . $ ot/::stcxx . . $ ot/st# error_code, const stdcxx . . $ std/::stringcxx . . $ std/string#& name) { |
| 142 | otcxx . . $ ot/::optionscxx . . $ ot/options# opt; |
| 143 | stdcxx . . $ std/::stringcxx . . $ std/string# txt = "N=1\nINVALID"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 144 | otcxx . . $ ot/::filecxx . . $ ot/file# input = fmemopencxx . . $ ot/file#file(8d4262d45fc644ab).((char*) txt.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), txt.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).(), "r"); |
| 145 | otcxx . . $ ot/::statuscxx . . $ ot/status# rc = parse_optionscxx . . $ parse_options(f7b722e81092e1ea).(args, opt, input.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()); |
| 146 | if (rc.codecxx . . $ ot/status#code. != error_code) |
| 147 | throw failurecxx . . $ tap/failure#("bad error code for case " +cxx . . $ std/operator+(42c652dfebe55ad7). name); |
| 148 | if (!rc.messagecxx . . $ ot/status#message..starts_withcxx . . $ std/__cxx11/basic_string#starts_with(a3d4f9b7451b6a5).(message)) |
| 149 | throw failurecxx . . $ tap/failure#("bad error message for case " +cxx . . $ std/operator+(42c652dfebe55ad7). name +cxx . . $ std/operator+(900ec9581c410ad9). ", got: " +cxx . . $ std/operator+(db5dc2ea912c6495). rc.messagecxx . . $ ot/status#message.); |
| 150 | }; |
| 151 | auto error_case = [&error_code_case](stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*> args, const char* message, const stdcxx . . $ std/::stringcxx . . $ std/string#& name) { |
| 152 | error_code_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_1#`operator()`(783758da71522ae).argscxx . . $ std/vector#vector(a1201200cf0efa42)., message, otcxx . . $ ot/::stcxx . . $ ot/st#::bad_argumentscxx . . $ ot/st#bad_arguments., name); |
| 153 | }; |
| 154 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags"}, "No arguments specified. Use -h for help.", "no arguments"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 155 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-a", "X"}, "Comment does not contain an equal sign: X.", "bad comment for -a"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 156 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--set", "X"}, "Comment does not contain an equal sign: X.", "bad comment for --set"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 157 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-a"}, "Missing value for option '-a'.", "short option with missing value"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 158 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-x"}, "Unrecognized option '-x'.", "unrecognized short option"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 159 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--derp"}, "Unrecognized option '--derp'.", "unrecognized long option"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 160 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-x=y"}, "Unrecognized option '-x'.", "unrecognized short option with value"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 161 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--derp=y"}, "Unrecognized option '--derp=y'.", "unrecognized long option with value"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 162 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-aX=Y"}, "Exactly one input file must be specified.", "no input file"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 163 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-i", "-o", "/dev/null", "-"}, "Cannot combine --in-place and --output.", "in-place + output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 164 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-S", "-"}, "Cannot use standard input more than once.", "set all and read opus from stdin"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 165 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-i", "-"}, "Cannot modify standard input in place.", "write stdin in-place"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 166 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-o", "x", "--output", "y", "z"}, |
| 167 | "Cannot specify --output more than once.", "double output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 168 | error_code_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_1#`operator()`(783758da71522ae).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-S", "x"}, "Malformed tag: INVALID", otcxx . . $ ot/::stcxx . . $ ot/st#::errorcxx . . $ ot/st#error., "attempt to read invalid argument with -S"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 169 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-o", "", "--output", "y", "z"}, |
| 170 | "Cannot specify --output more than once.", "double output with first filename empty"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 171 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-e", "-i", "x", "y"}, |
| 172 | "Exactly one input file must be specified.", "editing interactively two files at once"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 173 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "-", "-o", "x"}, |
| 174 | "Cannot edit interactively when standard input or standard output are already used.", |
| 175 | "editing interactively from stdandard intput"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 176 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x", "-o", "-"}, |
| 177 | "Cannot edit interactively when standard input or standard output are already used.", |
| 178 | "editing interactively to stdandard output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 179 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x"}, "Cannot edit interactively when no output is specified.", "editing without output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 180 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x", "-i", "-a", "X=Y"}, "Cannot mix --edit with -adDsS.", "mixing -e and -a"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 181 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x", "-i", "-d", "X"}, "Cannot mix --edit with -adDsS.", "mixing -e and -d"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 182 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x", "-i", "-D"}, "Cannot mix --edit with -adDsS.", "mixing -e and -D"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 183 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--edit", "x", "-i", "-S"}, "Cannot mix --edit with -adDsS.", "mixing -e and -S"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 184 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "--output-cover", "x", "--output-cover", "y"}, |
| 185 | "Cannot specify --output-cover more than once.", "multiple --output-cover"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 186 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "x", "-o", "-", "--output-cover", "-"}, |
| 187 | "Cannot specify standard output for both --output and --output-cover.", "-o and --output-cover conflict"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 188 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-i", "x", "y", "--output-cover", "z"}, |
| 189 | "Cannot use --output-cover with multiple input files.", "--output-cover with multiple input"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 190 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-i", "--vendor", "x"}, |
| 191 | "--vendor is only supported in read-only mode.", "--vendor when editing"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 192 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-d", "\xFF", "x"}, |
| 193 | "Could not encode argument into UTF-8:", |
| 194 | "-d with binary data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 195 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-a", "X=\xFF", "x"}, |
| 196 | "Could not encode argument into UTF-8:", |
| 197 | "-a with binary data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 198 | error_case(cxx . . $ check_bad_arguments(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(a11ba2a6c7e0dd50).{cxx . . $ std/vector#vector(9619226211e5a241)."opustags", "-s", "X=\xFF", "x"}, |
| 199 | "Could not encode argument into UTF-8:", |
| 200 | "-s with binary data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 201 | } |
| 202 | |
| 203 | static void check_delete_commentscxx . . $ check_delete_comments(49f6e7a06ebc5aa8).() |
| 204 | { |
| 205 | using Ccxx . . $ check_delete_comments(49f6e7a06ebc5aa8).C# = stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::u8stringcxx . . $ std/u8string#>; |
| 206 | Ccxx . . $ check_delete_comments(49f6e7a06ebc5aa8).C# original = {cxx . . $ std/__cxx11/list#list(9619226211e5a241).u8"TITLE=X", u8"Title=Y", u8"Title=Z", u8"ARTIST=A", u8"artIst=B"}; |
| 207 | |
| 208 | Ccxx . . $ check_delete_comments(49f6e7a06ebc5aa8).C# edited = originalcxx . . $ std/__cxx11/list#list(cb0950d04356f622).; |
| 209 | otcxx . . $ ot/::delete_commentscxx . . $ ot/delete_comments(e24a0c7c6463300e).(edited, u8"derp"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 210 | if (!stdcxx . . $ std/::equalcxx . . $ std/equal(51c87e3d44d61bd6).(edited.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), edited.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(), original.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), original.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).())) |
| 211 | throw failurecxx . . $ tap/failure#("should not have deleted anything"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 212 | |
| 213 | otcxx . . $ ot/::delete_commentscxx . . $ ot/delete_comments(e24a0c7c6463300e).(edited, u8"Title"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 214 | Ccxx . . $ check_delete_comments(49f6e7a06ebc5aa8).C# expected = {cxx . . $ std/__cxx11/list#list(9619226211e5a241).u8"ARTIST=A", u8"artIst=B"}; |
| 215 | if (!stdcxx . . $ std/::equalcxx . . $ std/equal(51c87e3d44d61bd6).(edited.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), edited.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(), expected.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), expected.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).())) |
| 216 | throw failurecxx . . $ tap/failure#("did not delete all titles correctly"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 217 | |
| 218 | edited =cxx . . $ std/__cxx11/list#`operator=`(c9d07eb90da1cabc). original; |
| 219 | otcxx . . $ ot/::delete_commentscxx . . $ ot/delete_comments(e24a0c7c6463300e).(edited, u8"titlE=Y"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 220 | otcxx . . $ ot/::delete_commentscxx . . $ ot/delete_comments(e24a0c7c6463300e).(edited, u8"Title=z"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 221 | expected =cxx . . $ std/__cxx11/list#`operator=`(e3262da308648e9d). {u8"TITLE=X", u8"Title=Z", u8"ARTIST=A", u8"artIst=B"}; |
| 222 | if (!stdcxx . . $ std/::equalcxx . . $ std/equal(51c87e3d44d61bd6).(edited.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), edited.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(), expected.begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).(), expected.endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).())) |
| 223 | throw failurecxx . . $ tap/failure#("did not delete a specific title correctly"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 224 | } |
| 225 | |
| 226 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 227 | { |
| 228 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "1..4\n"; |
| 229 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_read_commentscxx . . $ check_read_comments(49f6e7a06ebc5aa8)., "check tags parsing"); |
| 230 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_good_argumentscxx . . $ check_good_arguments(49f6e7a06ebc5aa8)., "check options parsing"); |
| 231 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_bad_argumentscxx . . $ check_bad_arguments(49f6e7a06ebc5aa8)., "check options parsing errors"); |
| 232 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_delete_commentscxx . . $ check_delete_comments(49f6e7a06ebc5aa8)., "delete comments"); |
| 233 | return 0; |
| 234 | } |