• R/O
  • SSH

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

Revision9736185df0c072a4c76a5306bd183938ddef91f5 (tree)
Zeit2023-01-16 05:55:45
AutorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Added CCompare to test CC2Cpy (Copy out IPython) + tests for it

Ändern Zusammenfassung

Diff

diff -r 7e55144de32d -r 9736185df0c0 Makefile
--- a/Makefile Sun Jan 15 18:37:57 2023 +0100
+++ b/Makefile Sun Jan 15 21:55:45 2023 +0100
@@ -1,6 +1,7 @@
11 default: all
22
3-CURRENT_TESTS = pytst/auxiliary/test_1_pack_mk_tuple.py \
3+CURRENT_TESTS = \
4+ pytst/writers/CC2Cpy/test_0.py \
45
56
67 all: current demo test pyanalyse XXX missing
@@ -25,8 +26,11 @@
2526 mutmut results
2627 open mutmut-report/index.html
2728
29+
2830 current:
2931 PYTHONPATH=`pwd` pytest ${PYTEST_OPTONS} ${CURRENT_TESTS}
32+current-ds current-sd:
33+ PYTHONPATH=`pwd` pytest ${PYTEST_OPTONS} --log-cli-level=DEBUG -s ${CURRENT_TESTS}
3034
3135
3236 demo: pytest-demo python-demo
diff -r 7e55144de32d -r 9736185df0c0 pytst/writers/CC2Cpy/__init__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/__init__.py Sun Jan 15 21:55:45 2023 +0100
@@ -0,0 +1,36 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+from typing import Generator
4+
5+__all__ = ['CCompare']
6+
7+
8+def CCompare(ref_code: str, try_code: str, log=True, log_all=False) ->bool:
9+ """"Compare two piece of (simple) C-code and return whether they are similar.
10+
11+ It ignores most whitespace, but not ATS-based. Make sure the ref in correctly formated!
12+
13+ Note: this is down-ported as zip(... strict=True) is python-3.10
14+ """
15+ if log_all: log=True
16+
17+ ref_tokens = text2tokens(ref_code)
18+ try_tokens = text2tokens(try_code)
19+ for a, b in zip(ref_tokens, try_tokens):
20+ if a != b:
21+ if log: print(f'{a}!={b}')
22+ return False
23+ if log_all: print(f'{a}')
24+ if len(list(ref_tokens)) == len(list(try_tokens)):
25+ return True
26+ #else
27+ if log: print("Not the same length")
28+ return False
29+
30+
31+def text2tokens(text: str) -> Generator[str, None, None]:
32+ for txt in text.split():
33+ for t in txt.split(';'):
34+ yield ';' if t=='' else t
35+
36+
diff -r 7e55144de32d -r 9736185df0c0 pytst/writers/CC2Cpy/test_0.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/test_0.py Sun Jan 15 21:55:45 2023 +0100
@@ -0,0 +1,28 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+from . import *
4+
5+from castle.writers.CC2Cpy import *
6+
7+LOG_ALL=True
8+
9+def test_0_trival_same():
10+ abc='A B C'
11+ assert CCompare(abc,abc, log_all=LOG_ALL)
12+
13+def test_1_not_same():
14+ abc='A B C'
15+ assert False == CCompare(abc,abc[::-1], log_all=LOG_ALL)
16+
17+def test_2_diff_length():
18+ abc=' A B C '
19+ assert False == CCompare(abc, abc+abc, log_all=LOG_ALL)
20+ assert False == CCompare(abc+abc, abc, log_all=LOG_ALL)
21+
22+def test_4_logvariants():
23+ abc=' A B C '
24+ assert CCompare(abc,abc, log=False, log_all=False)
25+ assert CCompare(abc,abc, log=False, log_all=True) # log=.. will be overiden
26+ assert CCompare(abc,abc, log=True , log_all=False)
27+ assert CCompare(abc,abc, log=True, log_all=True)
28+