|
| 1 | +import test from "ava"; |
| 2 | +import { Output } from "./output.ts"; |
| 3 | + |
| 4 | +test("append", (t) => { |
| 5 | + const output = new Output(100); |
| 6 | + t.is(String(output), ""); |
| 7 | + |
| 8 | + output.append("1"); |
| 9 | + t.is(String(output), "1"); |
| 10 | + |
| 11 | + output.separate(","); |
| 12 | + t.is(String(output), "1"); |
| 13 | + |
| 14 | + output.append("2"); |
| 15 | + t.is(String(output), "1,2"); |
| 16 | + |
| 17 | + output.append("3"); |
| 18 | + t.is(String(output), "1,23"); |
| 19 | + |
| 20 | + output.separate(""); |
| 21 | + output.append("4"); |
| 22 | + t.is(String(output), "1,234"); |
| 23 | + |
| 24 | + output.separate(";"); |
| 25 | + output.append(""); |
| 26 | + t.is(String(output), "1,234"); |
| 27 | + |
| 28 | + output.append("5"); |
| 29 | + t.is(String(output), "1,234;5"); |
| 30 | +}); |
| 31 | + |
| 32 | +test("limits", (t) => { |
| 33 | + const output = new Output(3); |
| 34 | + t.is(output.length, 0); |
| 35 | + t.is(output.remaining, 3); |
| 36 | + t.is(String(output), ""); |
| 37 | + |
| 38 | + output.append("1"); |
| 39 | + t.is(output.length, 1); |
| 40 | + t.is(output.remaining, 2); |
| 41 | + t.is(String(output), "1"); |
| 42 | + |
| 43 | + t.throws( |
| 44 | + () => { |
| 45 | + output.append("234"); |
| 46 | + }, |
| 47 | + { is: Output.Stop }, |
| 48 | + ); |
| 49 | + t.is(output.length, 1); |
| 50 | + t.is(output.remaining, 2); |
| 51 | + t.is(String(output), "1"); |
| 52 | + |
| 53 | + t.throws( |
| 54 | + () => { |
| 55 | + output.separate(",,,"); |
| 56 | + }, |
| 57 | + { is: Output.Stop }, |
| 58 | + ); |
| 59 | + t.is(output.length, 1); |
| 60 | + t.is(output.remaining, 2); |
| 61 | + t.is(String(output), "1"); |
| 62 | + |
| 63 | + output.separate(","); |
| 64 | + t.is(output.length, 2); |
| 65 | + t.is(output.remaining, 1); |
| 66 | + t.is(String(output), "1"); |
| 67 | + |
| 68 | + t.throws( |
| 69 | + () => { |
| 70 | + output.append("23"); |
| 71 | + }, |
| 72 | + { is: Output.Stop }, |
| 73 | + ); |
| 74 | + t.is(output.length, 2); |
| 75 | + t.is(output.remaining, 1); |
| 76 | + t.is(String(output), "1"); |
| 77 | + |
| 78 | + output.append("2"); |
| 79 | + t.is(output.length, 3); |
| 80 | + t.is(output.remaining, 0); |
| 81 | + t.is(String(output), "1,2"); |
| 82 | + |
| 83 | + output.clear(); |
| 84 | + t.is(output.length, 0); |
| 85 | + t.is(output.remaining, 3); |
| 86 | + t.is(String(output), ""); |
| 87 | +}); |
0 commit comments