Muspi Merol

Muspi Merol 的个人主页

马上订阅 Muspi Merol RSS 更新: https://muspimerol.site/feed

这个周末在抠 partial-json-parser

2024年5月12日 19:31

周五想到一种扁平的、2-pass 的实现,结果一直在 debug

扁平化的结果就是,要分类讨论很多很多情况,对我这种注意力不集中的人极其不友好🥲

我这种人大概是看不得 if-else 三层以上的算法的了😂




hypothesis 真是好啊,我准备把 js 版的也用 pythonmonkey 的 js runtime 接到 python 里,然后也用 hypothesis 来测一下。

欣赏一下 hypothesis 给出的报错:

  + Exception Group Traceback (most recent call last):
  |   File "<string>", line 1, in <module>
  |   File "D:\dev\partial-json-parser\tests\test_hypotheses.py", line 42, in main
  |     test_partial_json()
  |   File "D:\dev\partial-json-parser\tests\test_hypotheses.py", line 28, in test_partial_json
  |     @given(json)
  |
  |   File "D:\dev\partial-json-parser\.venv\Lib\site-packages\hypothesis\core.py", line 1638, in wrapped_test
  |     raise the_error_hypothesis_found
  | ExceptionGroup: Hypothesis found 3 distinct failures. (3 sub-exceptions)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "D:\dev\partial-json-parser\tests\test_hypotheses.py", line 34, in test_partial_json
    |     parse_json(json_string[:i])
    |   File "D:\dev\partial-json-parser\src\partial_json_parser\core\api.py", line 15, in parse_json
    |     return parser(ensure_json(json_string, allow_partial, use_fast_fix))
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

剩余内容已隐藏

查看完整文章以阅读更多