|
| 1 | +import { assert } from 'chai'; |
| 2 | +import sinon from 'sinon'; |
| 3 | +import File from '../../../File.js'; |
| 4 | +import { assertOutputAnswer } from '../../../assertOutputAnswer.js'; |
| 5 | +import { execute } from '../../../../lib/training/hard/CGXFormatter/CGXFormatter.js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests for the "CGX formatter" puzzle. |
| 9 | + */ |
| 10 | +suite('CGX formatter', function() { |
| 11 | + const sandbox = sinon.createSandbox(); |
| 12 | + |
| 13 | + setup(function () { |
| 14 | + sandbox.stub(console, "log"); |
| 15 | + }); |
| 16 | + |
| 17 | + teardown(function () { |
| 18 | + sandbox.restore(); |
| 19 | + }); |
| 20 | + |
| 21 | + |
| 22 | + test('Boolean value with spaces and tabs', function() { |
| 23 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/01 - boolean value with spaces and tabs.txt'); |
| 24 | + |
| 25 | + execute(inputFile.readline.bind(inputFile)); |
| 26 | + |
| 27 | + assert.strictEqual( |
| 28 | + console.log.getCall(0).args[0], |
| 29 | + "true" |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + test('Simple string of characters which must not be modified', function() { |
| 34 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/02 - simple string of characters which must not be modified.txt'); |
| 35 | + |
| 36 | + execute(inputFile.readline.bind(inputFile)); |
| 37 | + |
| 38 | + assert.strictEqual( |
| 39 | + console.log.getCall(0).args[0], |
| 40 | + "' Content with spaces and tabs'" |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Block containing a single value', function() { |
| 45 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/03 - block containing a single value.txt'); |
| 46 | + |
| 47 | + execute(inputFile.readline.bind(inputFile)); |
| 48 | + |
| 49 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/03 - block containing a single value.txt'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('Block containing multiple values', function() { |
| 53 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/04 - block containing a multiple values.txt'); |
| 54 | + |
| 55 | + execute(inputFile.readline.bind(inputFile)); |
| 56 | + |
| 57 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/04 - block containing a multiple values.txt'); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Nested blocks', function() { |
| 61 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/05 - nested blocks.txt'); |
| 62 | + |
| 63 | + execute(inputFile.readline.bind(inputFile)); |
| 64 | + |
| 65 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/05 - nested blocks.txt'); |
| 66 | + }); |
| 67 | + |
| 68 | + test('Empty block', function() { |
| 69 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/06 - empty block.txt'); |
| 70 | + |
| 71 | + execute(inputFile.readline.bind(inputFile)); |
| 72 | + |
| 73 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/06 - empty block.txt'); |
| 74 | + }); |
| 75 | + |
| 76 | + test('Block containing several blocks', function() { |
| 77 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/07 - block containing several blocks.txt'); |
| 78 | + |
| 79 | + execute(inputFile.readline.bind(inputFile)); |
| 80 | + |
| 81 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/07 - block containing several blocks.txt'); |
| 82 | + }); |
| 83 | + |
| 84 | + test('Key/value without blanks', function() { |
| 85 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/08 - key value without blanks.txt'); |
| 86 | + |
| 87 | + execute(inputFile.readline.bind(inputFile)); |
| 88 | + |
| 89 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/08 - key value without blanks.txt'); |
| 90 | + }); |
| 91 | + |
| 92 | + test('Block with several key/value', function() { |
| 93 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/09 - block with several key value.txt'); |
| 94 | + |
| 95 | + execute(inputFile.readline.bind(inputFile)); |
| 96 | + |
| 97 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/09 - block with several key value.txt'); |
| 98 | + }); |
| 99 | + |
| 100 | + test('Example provided', function() { |
| 101 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/10 - example provided.txt'); |
| 102 | + |
| 103 | + execute(inputFile.readline.bind(inputFile)); |
| 104 | + |
| 105 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/10 - example provided.txt'); |
| 106 | + }); |
| 107 | + |
| 108 | + test('Full example', function() { |
| 109 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/11 - full example.txt'); |
| 110 | + |
| 111 | + execute(inputFile.readline.bind(inputFile)); |
| 112 | + |
| 113 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/11 - full example.txt'); |
| 114 | + }); |
| 115 | + |
| 116 | + test('Numerous overlaps', function() { |
| 117 | + let inputFile = new File('./test/training/hard/CGXFormatter/input/12 - numerous overlaps.txt'); |
| 118 | + |
| 119 | + execute(inputFile.readline.bind(inputFile)); |
| 120 | + |
| 121 | + assertOutputAnswer('./test/training/hard/CGXFormatter/output/12 - numerous overlaps.txt'); |
| 122 | + }); |
| 123 | +}); |
0 commit comments