| 1 | package magic |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestTarParseOctal(t *testing.T) { |
| 6 | tests := []struct { |
| 7 | in string |
| 8 | want int64 |
| 9 | }{ |
| 10 | {"0000000\x00", 0}, |
| 11 | {" \x0000000\x00", 0}, |
| 12 | {" \x0000003\x00", 3}, |
| 13 | {"00000000227\x00", 0227}, |
| 14 | {"032033\x00 ", 032033}, |
| 15 | {"320330\x00 ", 0320330}, |
| 16 | {"0000660\x00 ", 0660}, |
| 17 | {"\x00 0000660\x00 ", 0660}, |
| 18 | {"0123456789abcdef", -1}, |
| 19 | {"0123456789\x00abcdef", -1}, |
| 20 | {"01234567\x0089abcdef", 01234567}, |
| 21 | {"0123\x7e\x5f\x264123", -1}, |
| 22 | } |
| 23 | |
| 24 | for _, tt := range tests { |
| 25 | got := tarParseOctal([]byte(tt.in)) |
| 26 | if got != tt.want { |
| 27 | t.Errorf("parseOctal(%q): got %d, want %d", tt.in, got, tt.want) |
| 28 | } |
| 29 | } |
| 30 | } |