1 // couples of input and expected result 2 immutable text = [[ 3 "some text\n" 4 "more text", 5 6 "some text\n" 7 "more text" 8 ], 9 [ 10 "// start with comments\n" 11 "some text // other comment\n" 12 "more text", 13 14 "\n" 15 "some text \n" 16 "more text" 17 ], 18 [ 19 "/ almost a comment but text\n" 20 "some text // an actual comment\n" 21 "more text", 22 23 "/ almost a comment but text\n" 24 "some text \n" 25 "more text" 26 ], 27 [ 28 "some text // comment\n" 29 "more text", 30 31 "some text \n" 32 "more text" 33 ], 34 [ 35 "some text # comment\n" 36 "more text", 37 38 "some text \n" 39 "more text" 40 ], 41 [ 42 "some text /* inlined comment */ more text", 43 44 "some text more text" 45 ], 46 [ 47 "some text /* comment with // inlined\n" 48 "over 2 lines */ more text", 49 50 "some text more text" 51 ], 52 [ 53 "some text // comment with /* inlined\n" 54 "more text", 55 56 "some text \n" 57 "more text" 58 ], 59 [ 60 "some text # comment with */ inlined\n" 61 "more text", 62 63 "some text \n" 64 "more text" 65 ], 66 [ 67 "some text /* multiline comment\n" 68 "still in comment\n" 69 "again comment */ more text", 70 71 "some text more text" 72 ]]; 73 74 foreach (t; text) { 75 import std.algorithm : equal; 76 import std.format : format; 77 import std.conv : to; 78 79 string input = t[0]; 80 string result = t[0].stripComments().to!string; 81 string expected = t[1]; 82 83 assert(equal(expected, result), format( 84 "stripComments test failed.\ninput:\n%s\nresult:\n%s\nexpected:\n%s\n", 85 input, result, expected 86 )); 87 } 88 89 foreach (t; text) { 90 import std.algorithm : equal; 91 import std.string : lineSplitter; 92 import std.format : format; 93 94 string [] input; 95 string [] result; 96 string [] expected; 97 foreach (s; t[0].lineSplitter) input ~= s; 98 foreach (s; t[0].lineSplitter.stripComments) result ~= s; 99 foreach (s; t[1].lineSplitter) expected ~= s; 100 101 assert(equal(expected, result), format( 102 "lineSplitter.stripComments test failed.\ninput:\n%s\nresult:\n%s\nexpected:\n%s\n", 103 input, result, expected 104 )); 105 }
strip libconfig comments on a line by line basis