From 469ed76dd3ec1aebea48fb3d00f54b0eceaac0e6 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 8 Aug 2023 18:29:35 +0100 Subject: [PATCH] First attempt to reduce test case. --- src/config.nim | 2 +- tests/{test1.nim => notest1.nim} | 0 tests/{test2.nim => notest2.nim} | 0 tests/test3.nim | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) rename tests/{test1.nim => notest1.nim} (100%) rename tests/{test2.nim => notest2.nim} (100%) create mode 100644 tests/test3.nim diff --git a/src/config.nim b/src/config.nim index 40281d9..64ec5c1 100644 --- a/src/config.nim +++ b/src/config.nim @@ -1642,7 +1642,7 @@ var IDENTIFIER_PATTERN = re(r"(*U)^(?!\d)(\w+)$") proc isIdentifier(s: string): bool = s.match(IDENTIFIER_PATTERN).isSome -proc parsePath(s: string): ASTNode = +proc parsePath*(s: string): ASTNode = proc fail(loc: Location) = raise newConfigError(&"invalid path: {s}", loc) diff --git a/tests/test1.nim b/tests/notest1.nim similarity index 100% rename from tests/test1.nim rename to tests/notest1.nim diff --git a/tests/test2.nim b/tests/notest2.nim similarity index 100% rename from tests/test2.nim rename to tests/notest2.nim diff --git a/tests/test3.nim b/tests/test3.nim new file mode 100644 index 0000000..e520e86 --- /dev/null +++ b/tests/test3.nim @@ -0,0 +1,38 @@ +# +# Copyright 2016-2023 by Vinay Sajip. All Rights Reserved. +# +import complex +import os +import strutils +import tables +import times +import typetraits +import unittest + +import ../src/config + +proc dataFilePath(paths: varargs[string]): string = + "tests" / "resources" / paths.join("/") + +# +# Config +# + +proc CV(s: string): ConfigValue = + ConfigValue(kind: StringValue, stringValue: s) + + +test "main config": + var p = dataFilePath("derived", "main.cfg") + var cfg = newConfig() + cfg.includePath.add(dataFilePath("base")) + cfg.loadFile(p) + + var lcfg = cfg.getSubConfig("logging") + var ev = CV("bar") + check ev == lcfg.get("foo.bar", ev) + #ev.stringValue = "bozz" + echo "Before test" + discard parsePath("handlers.debug.lvl") + #check ev == lcfg.get("handlers.debug.lvl", ev) + echo "After test"