(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestDispenser_Val_Next(t *testing.T) { |
| 25 | input := `host:port |
| 26 | dir1 arg1 |
| 27 | dir2 arg2 arg3 |
| 28 | dir3` |
| 29 | d := NewTestDispenser(input) |
| 30 | |
| 31 | if val := d.Val(); val != "" { |
| 32 | t.Fatalf("Val(): Should return empty string when no token loaded; got '%s'", val) |
| 33 | } |
| 34 | |
| 35 | assertNext := func(shouldLoad bool, expectedCursor int, expectedVal string) { |
| 36 | if loaded := d.Next(); loaded != shouldLoad { |
| 37 | t.Errorf("Next(): Expected %v but got %v instead (val '%s')", shouldLoad, loaded, d.Val()) |
| 38 | } |
| 39 | if d.cursor != expectedCursor { |
| 40 | t.Errorf("Expected cursor to be %d, but was %d", expectedCursor, d.cursor) |
| 41 | } |
| 42 | if d.nesting != 0 { |
| 43 | t.Errorf("Nesting should be 0, was %d instead", d.nesting) |
| 44 | } |
| 45 | if val := d.Val(); val != expectedVal { |
| 46 | t.Errorf("Val(): Expected '%s' but got '%s'", expectedVal, val) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | assertNext(true, 0, "host:port") |
| 51 | assertNext(true, 1, "dir1") |
| 52 | assertNext(true, 2, "arg1") |
| 53 | assertNext(true, 3, "dir2") |
| 54 | assertNext(true, 4, "arg2") |
| 55 | assertNext(true, 5, "arg3") |
| 56 | assertNext(true, 6, "dir3") |
| 57 | // Note: This next test simply asserts existing behavior. |
| 58 | // If desired, we may wish to empty the token value after |
| 59 | // reading past the EOF. Open an issue if you want this change. |
| 60 | assertNext(false, 6, "dir3") |
| 61 | } |
| 62 | |
| 63 | func TestDispenser_NextArg(t *testing.T) { |
| 64 | input := `dir1 arg1 |
nothing calls this directly
no test coverage detected