| 68 | } |
| 69 | |
| 70 | func TestNewCmdReadFile(t *testing.T) { |
| 71 | tests := []struct { |
| 72 | name string |
| 73 | args string |
| 74 | wantOpts ReadFileOptions |
| 75 | wantErr string |
| 76 | }{ |
| 77 | { |
| 78 | name: "path only", |
| 79 | args: "README.md", |
| 80 | wantOpts: ReadFileOptions{ |
| 81 | Path: "README.md", |
| 82 | }, |
| 83 | }, |
| 84 | { |
| 85 | name: "with ref", |
| 86 | args: "README.md --ref v1.2.3", |
| 87 | wantOpts: ReadFileOptions{ |
| 88 | Path: "README.md", |
| 89 | Ref: "v1.2.3", |
| 90 | }, |
| 91 | }, |
| 92 | { |
| 93 | name: "with output and clobber", |
| 94 | args: "README.md --output out.md --clobber", |
| 95 | wantOpts: ReadFileOptions{ |
| 96 | Path: "README.md", |
| 97 | Output: "out.md", |
| 98 | Clobber: true, |
| 99 | }, |
| 100 | }, |
| 101 | { |
| 102 | name: "with allow-escape-sequences", |
| 103 | args: "README.md --allow-escape-sequences", |
| 104 | wantOpts: ReadFileOptions{ |
| 105 | Path: "README.md", |
| 106 | AllowEscapeSequences: true, |
| 107 | }, |
| 108 | }, |
| 109 | { |
| 110 | name: "no arguments", |
| 111 | args: "", |
| 112 | wantErr: "accepts 1 arg(s), received 0", |
| 113 | }, |
| 114 | { |
| 115 | name: "too many arguments", |
| 116 | args: "a.md b.md", |
| 117 | wantErr: "accepts 1 arg(s), received 2", |
| 118 | }, |
| 119 | { |
| 120 | name: "json and output are mutually exclusive", |
| 121 | args: "README.md --json name --output out.md", |
| 122 | wantErr: "specify only one of `--json` or `--output`", |
| 123 | }, |
| 124 | } |
| 125 | |
| 126 | for _, tt := range tests { |
| 127 | t.Run(tt.name, func(t *testing.T) { |