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