Skip to content

Commit 60e36ae

Browse files
committed
fix: work around D-YAML off-by-one error
This is issue #5 and a pre-requisite to be able to implement the ability to have no line / column information.
1 parent bc1348d commit 60e36ae

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

source/configy/attributes.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,5 @@ unittest {
399399
status: expatriate
400400
`, "/etc/config");
401401
catch (ConfigException exc)
402-
assert(exc.toString() == `/etc/config(2:12): countries[0].status: expatriate is not a valid value for this field, valid values are: "citizen", "resident", "alien"`);
402+
assert(exc.toString() == `/etc/config(3:13): countries[0].status: expatriate is not a valid value for this field, valid values are: "citizen", "resident", "alien"`);
403403
}

source/configy/exceptions.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,6 @@ package struct Location {
416416
/// Helper function
417417
package static Location get (Node n) @safe pure nothrow @nogc {
418418
auto m = n.startMark();
419-
return Location(m.name, m.line, m.column);
419+
return Location(m.name, m.line + 1, m.column + 1);
420420
}
421421
}

source/configy/test.d

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ unittest
125125
}
126126
catch (Exception exc)
127127
{
128-
assert(exc.toString() == "/dev/null(1:10): node.timeout: Field is of type scalar, " ~
128+
assert(exc.toString() == "/dev/null(2:11): node.timeout: Field is of type scalar, " ~
129129
"but expected a mapping with at least one of: weeks, days, hours, minutes, " ~
130130
"seconds, msecs, usecs, hnsecs, nsecs");
131131
}
@@ -144,9 +144,9 @@ unittest
144144
catch (ConfigException e)
145145
{
146146
assert(format("%s", e) ==
147-
"/dev/null(0:0): value: Key is not a valid member of this section. There are 1 valid keys: required");
147+
"/dev/null(1:1): value: Key is not a valid member of this section. There are 1 valid keys: required");
148148
assert(format("%S", e) ==
149-
format("%s/dev/null%s(%s0%s:%s0%s): %svalue%s: Key is not a valid member of this section. " ~
149+
format("%s/dev/null%s(%s1%s:%s1%s): %svalue%s: Key is not a valid member of this section. " ~
150150
"There are %s1%s valid keys: %srequired%s", Yellow, Reset, Cyan, Reset, Cyan, Reset,
151151
Yellow, Reset, Yellow, Reset, Green, Reset));
152152
}
@@ -174,7 +174,7 @@ unittest
174174
}
175175
catch (ConfigException exc)
176176
{
177-
assert(exc.toString() == "/dev/null(0:5): map: Expected to be a mapping (object), but is a scalar");
177+
assert(exc.toString() == "/dev/null(1:6): map: Expected to be a mapping (object), but is a scalar");
178178
}
179179

180180
try
@@ -184,7 +184,7 @@ unittest
184184
}
185185
catch (ConfigException exc)
186186
{
187-
assert(exc.toString() == "/dev/null(1:2): map: Expected to be a mapping (object), but is a sequence");
187+
assert(exc.toString() == "/dev/null(2:3): map: Expected to be a mapping (object), but is a sequence");
188188
}
189189

190190
try
@@ -194,7 +194,7 @@ unittest
194194
}
195195
catch (ConfigException exc)
196196
{
197-
assert(exc.toString() == "/dev/null(1:2): scalar: Expected to be a value of type int, but is a sequence");
197+
assert(exc.toString() == "/dev/null(2:3): scalar: Expected to be a value of type int, but is a sequence");
198198
}
199199

200200
try
@@ -204,7 +204,7 @@ unittest
204204
}
205205
catch (ConfigException exc)
206206
{
207-
assert(exc.toString() == "/dev/null(1:2): scalar: Expected to be a value of type int, but is a mapping");
207+
assert(exc.toString() == "/dev/null(2:3): scalar: Expected to be a value of type int, but is a mapping");
208208
}
209209
}
210210

@@ -225,7 +225,7 @@ unittest
225225
}
226226
catch (ConfigException exc)
227227
{
228-
assert(exc.toString() == "/dev/null(0:0): valeu: Key is not a valid member of this section. Did you mean: value, valhu");
228+
assert(exc.toString() == "/dev/null(1:1): valeu: Key is not a valid member of this section. Did you mean: value, valhu");
229229
}
230230
}
231231

@@ -250,7 +250,7 @@ unittest
250250
}
251251
catch (ConfigException exc)
252252
{
253-
assert(exc.toString() == "/dev/null(1:2): inner.required: Required key was not found in configuration or command line arguments");
253+
assert(exc.toString() == "/dev/null(2:3): inner.required: Required key was not found in configuration or command line arguments");
254254
}
255255
}
256256

@@ -372,7 +372,7 @@ unittest
372372
}
373373
catch (ConfigException exc)
374374
{
375-
assert(exc.toString() == "/dev/null(2:8): config.ctor: Something went wrong... Obviously");
375+
assert(exc.toString() == "/dev/null(3:9): config.ctor: Something went wrong... Obviously");
376376
}
377377

378378
try
@@ -382,7 +382,7 @@ unittest
382382
}
383383
catch (ConfigException exc)
384384
{
385-
assert(exc.toString() == "/dev/null(2:14): config.fromString: Some meaningful error message");
385+
assert(exc.toString() == "/dev/null(3:15): config.fromString: Some meaningful error message");
386386
}
387387

388388
try
@@ -392,7 +392,7 @@ unittest
392392
}
393393
catch (ConfigException exc)
394394
{
395-
assert(exc.toString() == "/dev/null(3:4): config.validated: Bad data, try again");
395+
assert(exc.toString() == "/dev/null(4:5): config.validated: Bad data, try again");
396396
}
397397

398398
try
@@ -402,7 +402,7 @@ unittest
402402
}
403403
catch (ConfigException exc)
404404
{
405-
assert(exc.toString() == "/dev/null(2:13): config.converter: You shall not pass");
405+
assert(exc.toString() == "/dev/null(3:14): config.converter: You shall not pass");
406406
}
407407

408408
// We also need to test with arrays, to ensure they are correctly called
@@ -425,7 +425,7 @@ unittest
425425
}
426426
catch (ConfigException exc)
427427
{
428-
assert(exc.toString() == "/dev/null(1:10): configs[0].ctor: Something went wrong... Obviously");
428+
assert(exc.toString() == "/dev/null(2:11): configs[0].ctor: Something went wrong... Obviously");
429429
}
430430

431431
try
@@ -436,7 +436,7 @@ unittest
436436
}
437437
catch (ConfigException exc)
438438
{
439-
assert(exc.toString() == "/dev/null(2:16): configs[1].fromString: Some meaningful error message");
439+
assert(exc.toString() == "/dev/null(3:17): configs[1].fromString: Some meaningful error message");
440440
}
441441
}
442442

@@ -509,7 +509,7 @@ unittest
509509
}
510510
catch (ConfigException exc)
511511
{
512-
assert(exc.toString() == "<unknown>(0:0): chris.jay: Required key was not found in configuration or command line arguments", exc.toString());
512+
assert(exc.toString() == "<unknown>(1:1): chris.jay: Required key was not found in configuration or command line arguments", exc.toString());
513513
}
514514
}
515515

@@ -712,7 +712,7 @@ unittest
712712
- Working
713713
`, "/dev/null");
714714
catch (Exception exc)
715-
assert(exc.toString() == `/dev/null(2:6): data.array[0]: Parsing failed!`);
715+
assert(exc.toString() == `/dev/null(3:7): data.array[0]: Parsing failed!`);
716716
}
717717

718718
/// Test for error message: Has to be versioned out, uncomment to check manually
@@ -901,7 +901,7 @@ dynamic:
901901
- value: 840
902902
`, "/dev/null");
903903
catch (ConfigException e)
904-
assert(e.toString() == "/dev/null(0:0): static: Required key was not found in configuration or command line arguments");
904+
assert(e.toString() == "/dev/null(1:1): static: Required key was not found in configuration or command line arguments");
905905

906906
try parseConfigString!Config(`fixed:
907907
value: 42
@@ -913,7 +913,7 @@ dynamic:
913913
- value: 840
914914
`, "/dev/null");
915915
catch (ConfigException e)
916-
assert(e.toString() == "/dev/null(3:2): static: Too few entries for sequence: Expected 3, got 2");
916+
assert(e.toString() == "/dev/null(4:3): static: Too few entries for sequence: Expected 3, got 2");
917917

918918
try parseConfigString!Config(`fixed:
919919
value: 42
@@ -927,7 +927,7 @@ dynamic:
927927
- value: 840
928928
`, "/dev/null");
929929
catch (ConfigException e)
930-
assert(e.toString() == "/dev/null(3:2): static: Too many entries for sequence: Expected 3, got 4");
930+
assert(e.toString() == "/dev/null(4:3): static: Too many entries for sequence: Expected 3, got 4");
931931

932932
// Check that optional static array work
933933
static struct ConfigOpt
@@ -976,15 +976,15 @@ ds:
976976
disabled: MAYBE
977977
`, "/dev/null");
978978
catch (ConfigException exc)
979-
assert(exc.toString() == "/dev/null(3:12): ds.disabled: Expected to be a value of type bool, but is a scalar");
979+
assert(exc.toString() == "/dev/null(4:13): ds.disabled: Expected to be a value of type bool, but is a scalar");
980980

981981
try parseConfigString!Config(`es:
982982
enabled: PERHAPS
983983
ds:
984984
disabled: true
985985
`, "/dev/null");
986986
catch (ConfigException exc)
987-
assert(exc.toString() == "/dev/null(1:11): es.enabled: Expected to be a value of type bool, but is a scalar");
987+
assert(exc.toString() == "/dev/null(2:12): es.enabled: Expected to be a value of type bool, but is a scalar");
988988
}
989989

990990
/// Test pointers

0 commit comments

Comments
 (0)