From 868d2af03d0f39dcdf405743f1ed56e8a69bdf82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sat, 13 Jul 2024 23:06:15 +0300 Subject: [PATCH] d --- py/cfg_aux_test.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ py/cfg_test.py | 22 ++++++++++++++++++++++ py/do-test.py | 20 ++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 py/cfg_aux_test.py create mode 100644 py/cfg_test.py create mode 100755 py/do-test.py diff --git a/py/cfg_aux_test.py b/py/cfg_aux_test.py new file mode 100644 index 0000000..4909b71 --- /dev/null +++ b/py/cfg_aux_test.py @@ -0,0 +1,47 @@ +from cfg_aux import * + +def test_cfg_aux_tree( +) -> str: + lines = [ + "[abc]", + "width = 100", + "wrongSep=another", + "[def]", + "anotherWrongSep -> whatever", + "title = yo", + "subtitle = whoa", + ] + tree = cfg_aux_tree(lines) + if ( + cld_len(tree) == 2 and + cld_len(tree["abc"]) == 1 and + cld_len(tree["def"]) == 2 + ): + return "OK: cfg_aux_tree" + return "ERR: cfg_aux_tree" + +def test_cfg_aux_treeCreateSection( +) -> str: + tree: dict[str, dict[str, str]] = {} + line = "[abc]" + sectionName = cfg_aux_treeCreateSection(tree, line) + if ( + sectionName == "abc" and + cld_len(tree) == 1 + ): + return "OK: cfg_aux_treeCreateSection" + return "ERR: cfg_aux_treeCreateSection" + +def test_cfg_aux_treeSetKeyValue( +) -> str: + tree: dict[str, dict[str, str]] = {} + line = "[abc]" + sectionName = cfg_aux_treeCreateSection(tree, line) + line = "title = wazup" + cfg_aux_treeSetKeyValue(tree, sectionName, line) + if ( + cld_len(tree[sectionName]) == 1 and + tree[sectionName]["title"] == "wazup" + ): + return "OK: cfg_aux_treeSetKeyValue" + return "ERR: cfg_aux_treeSetKeyValue" diff --git a/py/cfg_test.py b/py/cfg_test.py new file mode 100644 index 0000000..4dec24e --- /dev/null +++ b/py/cfg_test.py @@ -0,0 +1,22 @@ +from cfg import * +from ht_Context import * + +def test_cfg_parseConfigTree( +) -> str: + c = ht_createContext() + c.cfgContents = [ + "[abc]", + "width = 100", + "wrongSep=another", + "[def]", + "anotherWrongSep -> whatever", + "title = yo", + "subtitle = whoa", + ] + c.recentField = "cfgContents" + c = cfg_parseConfigTree(c) + if ( + cld_len(c.cfgTree) == 2 + ): + return "OK: cfg_parseConfigTree" + return "ERR: cfg_parseConfigTree" diff --git a/py/do-test.py b/py/do-test.py new file mode 100755 index 0000000..a1f7729 --- /dev/null +++ b/py/do-test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import os +import sys + +SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) +sys.path.append(f"{SCRIPT_DIR}/../../cross-language-dialect/lib") + +from cfg_aux_test import * +from cfg_test import * + +functions = [ + test_cfg_parseConfigTree, + test_cfg_aux_tree, + test_cfg_aux_treeCreateSection, + test_cfg_aux_treeSetKeyValue, +] + +for f in functions: + print(f())