1
0
mirror of synced 2024-12-03 18:57:16 +01:00

Merge pull request #10 from Stepland/fix-bugs-found-by-nomlas

Fix bugs found by Nomlas
This commit is contained in:
Stepland 2021-05-22 13:03:26 +02:00 committed by GitHub
commit b48911d8f2
9 changed files with 567 additions and 18 deletions

View File

@ -20,7 +20,7 @@ jobs:
- name: Code style
run: |
poetry run isort --check-only
poetry run black --check
poetry run black --check jubeatools
- name: Lint code
run: poetry run sh ./utils/check_code.sh
- name: Unit tests

View File

@ -1,3 +1,12 @@
# Unreleased
## Fixed
- [jubeat-analyser]
- Accept U+3000 (Ideographic space) as valid whitespace everywhere
- [memo2]
- Accept `t=` commands anywhere in the file
- Accept `b=4` (and only 4) anywhere in the file
# v1.1.1
## Fixed
- `construct-typing` is now required for all builds

View File

@ -48,7 +48,7 @@ command_grammar = Grammar(
value_in_quotes = '"' quoted_value '"'
quoted_value = ~r"([^\"\\]|\\\"|\\\\)*"
number = ~r"-?\d+(\.\d+)?"
ws = ~r"[\t ]*"
ws = ~r"[\t \u3000]*"
comment = ~r"//.*"
"""
)

View File

@ -83,7 +83,7 @@ double_column_chart_line_grammar = Grammar(
line = ws position_part ws (timing_part ws)? comment?
position_part = ~r"[^*#:|/\s]{4,8}"
timing_part = "|" ~r"[^*#:|/\s]*" "|"
ws = ~r"[\t ]*"
ws = ~r"[\t \u3000]*"
comment = ~r"//.*"
"""
)

View File

@ -102,7 +102,7 @@ memo2_chart_line_grammar = Grammar(
bpm = "(" float ")"
float = ~r"\d+(\.\d+)?"
notes = ~r"[^*#:\(\[|/\s]+"
ws = ~r"[\t ]*"
ws = ~r"[\t \u3000]*" # U+03000 : IDEOGRAPHIC SPACE
comment = ~r"//.*"
"""
)
@ -180,20 +180,16 @@ class Memo2Parser(JubeatAnalyserParser):
self.frames: List[Memo2Frame] = []
def do_b(self, value: str) -> None:
raise RuntimeError(
"beat command (b=...) found, this commands cannot be used in #memo2 files"
)
if Decimal(value) != 4:
raise RuntimeError(
"Beat command (b=...) found with a value other that 4, this is "
"unexpected in #memo2 files. If you are sure the file is not "
"just actually a #memo1 or #memo file with the wrong format "
"tag, you're welcome to report this error as a bug"
)
def do_t(self, value: str) -> None:
if self.frames:
raise RuntimeError(
"tempo command (t=...) found outside of the file header, "
"this should not happen in #memo2 files"
)
else:
self.timing_events.append(
BPMEvent(self._current_beat(), BPM=Decimal(value))
)
self.timing_events.append(BPMEvent(self._current_beat(), BPM=Decimal(value)))
def do_r(self, value: str) -> None:
if self.frames:

View File

@ -42,7 +42,7 @@ mono_column_chart_line_grammar = Grammar(
r"""
line = ws chart_line ws comment?
chart_line = ~r"[^*#:|\-/\s]{4,8}"
ws = ~r"[\t ]*"
ws = ~r"[\t \u3000]*"
comment = ~r"//.*"
"""
)

View File

@ -12,7 +12,7 @@ beat_symbol_line_grammar = Grammar(
line = "*" symbol ":" number comment?
symbol = ws ~r"[^*#:|\-/\s]{1,2}" ws
number = ws ~r"\d+(\.\d+)?" ws
ws = ~r"\s*"
ws = ~r"[\t \u3000]*"
comment = ~r"//.*"
"""
)

View File

@ -0,0 +1,530 @@
m="Booths of Fighters.mp3"
o=2320
t=225
b=4.0
#memo2
□□①□   |①---|
④□②□   |②---|
□□③□   |③---|
□□□⑤   |④-⑤-|
□③□□   |①---|
□⑤□①   |②-③-|
④⑦□□   |④-⑤-|
⑥□②□   |⑥-⑦-|
□□□①   |①---|
④□□②   |②---|
□□□③   |③---|
□□□⑤   |④-⑤-|
③②□□   |①-②-|
□□①④   |③-④-|
□□□□   |⑤-⑥-|
⑤⑥⑦⑧   |⑦-⑧-|
□□①①   |①---|
④□②□   |②---|
□□③□   |③---|
□□□⑤   |④-⑤-|
□③□□   |①---|
□□□①   |②-③-|
④□□□   |④---|
⑤□②⑥   |⑤-⑥-|
①□□①   |①---|
□□□②   |②---|
④□□③   |③---|
□□⑤□   |④-⑤-|
③③③③   |①---|
□②①□   |②-③-|
□①②□   ||
□□□□   ||
□②②□   |①---|
①□□①   ||
④③③□   |②-③-|
①④□①   |--④-|
□□□□   |--①-|
④□①□   ||
□□□①   |--②-|
②□③□   |③-④-|
□□□①   |①---|
□②②□   ||
④□①□   |②-③-|
③④□③   |--④-|
⑤②□□   |--①-|
②□□①   |--②-|
□③①□   |--③-|
□□④□   |④-⑤-|
□⑤⑤□   |①---|
□①①□   |②-③-|
□□□③   |--④-|
②□□④   |⑤---|
⑤□□⑤   |①---|
□□□②   |②-③-|
③④④□   |--④-|
□①①□   |⑤---|
□③③□   |①---|
⑥②②④   |②-③-|
□⑤⑤□   |--④-|
①□□①   |⑤-⑥-|
①③③①   |①-②-|
□③③□   |--③-|
□□□□   ||
②②②②   ||
①□□□   |①-②-|
③□□③   |③---|
④④□①   |④---|
⑤□⑤②   |⑤---|
①⑤⑤①   |①-②-|
③③□□   |③-④-|
⑤□□②   |⑤---|
⑥④□⑥   |⑥---|
①□⑦①   |①-②-|
③□③⑤   |③-④-|
⑤□②⑥   |⑤-⑥-|
⑦⑧④□   |⑦-⑧-|
①①□③   |①-②-|
③□④□   |③-④-|
⑤⑤□⑥   |⑤---|
⑥□⑤②   |⑥---|
①□①□   |①-②-|
③④□②   |③-④-|
⑤⑥⑤⑧   |⑤-⑥-|
⑦⑦□③   |⑦-⑧-|
①□⑥①   |①-②-|
③□③②   |③-④-|
⑤□□□   |⑤-⑥-|
⑦⑦⑤④   |⑦---|
①□□④   |①-②③|
⑥⑤⑤③   |④---|
⑦①①②   |⑤-⑥⑦|
⑧□□⑤   |⑧---|
①①□③   |①-②-|
□□□⑤   |③-④-|
□④②□   |⑤---|
□⑥⑥□   |⑥---|
①□①⑤   |①---|
②②□□   |②-③-|
④□④③   |④-⑤-|
⑥⑥□⑦   |⑥-⑦-|
①□①□   |①-②-|
③⑥④②   |③-④-|
⑤⑤□⑦   |⑤-⑥-|
⑦□③⑧   |⑦-⑧-|
①⑥⑧①   |①-②-|
③□□②   |③-④-|
⑤□③□   |⑤-⑥-|
⑦④⑤□   |⑦-⑧-|
①□□□   |①---②③④⑤|
⑤④③②   |----⑥⑦⑧⑨|
⑨⑧⑦⑥   |----⑩⑪⑫⑬| 
⑬⑫⑪⑩  
⑰⑯⑮⑭  
□□□□  
□□□□ 
□□□□   |----⑭⑮⑯⑰|
□□□□   ||
①□①□   |①---|
②②□③   |②-③-|
□□④⑤   |④-⑤-|
①□②①   |①-②-|
④②□④   |--③-|
□□⑤⑤   |④-⑤-|
③③□□   ||
□⑤□⑧   |①-②-|
⑦□③□   |③-④-|
□②□⑥   |⑤-⑥-|
④□□①   |⑦-⑧-|
⑥⑥②□   |①-②-|
□③□□   |③-④-|
□□④□   |⑤---|
⑤①①□   |⑥---|
□□④③   |①---|
②□①①   ||
□①□①   |②---|
□①②①   |③-④-|
□□□□   |①---|
□□□□   |②-③-|
①□□②   ||
□□□③   ||
①①⑥②   |①---|
①⑤①②   |②---|
①①④②   |③-④-|
□③□□   |⑤-⑥-|
□□□□   |①-②-|
①□□□   |③-④-|
④②□□   ||
④□□③   ||
□①□①   |①---|
③□①③   |--②-|
④□①④   |③---|
□②①□   |④---|
①⑥⑥④   |①-②-|
□□②□   |③-④-|
□③□□   |⑤-⑥-|
□□□⑤   ||
⑤□□□   |①---|
□①④②   ||
①□①□   |②-③-|
①③①□   |④-⑤-|
□□□□   |①-②-|
③□□⑤   |③-④-|
□②□□   |⑤-⑥-|
④⑥⑥①   ||
□⑤①①   |①---|
□①□□   ||
②④①①   |②-③-|
□□③□   |④-⑤-|
□□□①   |①-②-|
□③□④   |③---|
□□②④   |④---|
□□□①   ||
①①□②   |①---|
①⑤□□   ||
③①□□   |②-③-|
①①④□   |④-⑤-|
①③③□   |①---|
□□□□   |②-③-|
□②□□   ||
①□□□   ||
④□□□   |①---|
□□①③   ||
⑤□①①   |②-③-|
②□①①   |④-⑤-|
□□□①   |①-②-|
□□□□   |③---|
□□□②   ||
□③③①   ||
□①③□   |①---|
①③①□   ||
①□①②   |②---|
②□□□   |③---|
t=200
④④□□   |①--②|
□□③③   |--③-|
②②□□   |④---|
□□①①   ||
t=175
□②□□   |①---|
②□□□   ||
□□□②   |②---|
①①①①   ||
④□□□   |①-②-|
□③②①   |③---|
④□□□   |④---|
□□⑤⑤   |⑤---|
②□①□   |①---|
□□□①   ||
□①②□   |②---|
□②□□   ||
□□□①   |①---|
□□④□   |②-③-|
□②□③   |④---|
⑤⑤□④   |⑤---|
□□①②   |①---|
□②□①   ||
①□□□   |②---|
□□②□   ||
□□□□   |①-②-|
④□□□   |③---|
①②③□   |④---|
④□□④   ||
②□①□   |①---|
□□□①   ||
②□□□   |②---|
□①□□   ||
③②□④   |①---|
②①□□   |②-③-|
□④①②   |④---|
①□④□   ||
④□④□   |①--②|
□③①④   |--③-|
③□②□   |④---|
①①□②   ||
□□□⑤   |①-②-|
④□□□   |③---|
□③②①   |④---|
①□□□   |⑤---|
⑤⑤②□   |①-②-|
□④④②   |③-④-|
①□□⑤   |⑤---|
□①③③   ||
□④□①   |①---|
□□⑤⑤   |②-③-|
④⑥②③   |④-⑤-|
⑥⑦⑦□   |⑥-⑦-|
④③□①   |①--②|
②①④□   |--③-|
④□②③   |④---|
□□□①   ||
□⑥⑤□   |①-②-|
⑤□□⑥   |③---|
□⑤⑥④   |④---|
□③②①   |⑤-⑥-|
①□□①   |①---|
□①①□   ||
②③④②   |②-③-|
□③④□   |④---|
t=155
④①②④   |①--②|
①③③②   |--③-|
□④④□   |④---|
②□□①   
□⑤□□  
⑤□□□   
□□□⑤   
□□⑤□   |⑤---|
t=225
□□□□   |①---|
□□□□   ||
□□□□   ||
①□□①   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
①□□□   |①---|
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□④   |①---|
□□□③   |②---|
①①□②   |③---|
□□□①   |④---|
①①④□   |①---|
□□③□   |②---|
□□②□   |③---|
□□①□   |④---|
□□□④   |①---|
①①□③   |②---|
□□□②   |③---|
□□□①   |④---|
①①④□   |①---|
□□③□   |②---|
□□②□   |③---|
□□①□   |④---|
□⑩⑪⑫   |①②③|
⑦⑧⑨□   |④⑤⑥|
□④⑤⑥   |⑦⑧⑨|
①②③□   |⑩⑪⑫|
⑦⑧□□   |①②③|
⑤⑥□②   |④--|
③□□⑧   |⑤⑥⑦|
①□⑧④   |⑧--|
⑦□⑤⑤   |①②③|
□□③③   |④--|
④②②⑧   |⑤--|
①①⑥⑥   |⑥⑦⑧|
□⑤⑤□   |①②③|
③③□④   |④--|
□②②□   |⑤--|
①①⑦⑥   |⑥-⑦|
①□③①   |①--|
③□□⑥   |②--|
⑤⑤□□   |③--|
②②□④   |④⑤⑥|
①①□⑥   |①②③|
⑤②②□   |④--|
⑨□③③   |⑤⑥⑦|
④⑦⑩⑧   |⑧⑨⑩|
①①⑥⑥   |①②③|
⑤②②⑤   |④--|
□□③③   |⑤--|
④⑦□⑧   |⑥⑦⑧|
①①⑦⑦   |①②③|
⑤②②□   |④--|
③③□④   |⑤-⑥|
⑤⑧⑥□   |⑦-⑧|
①①④□   |①⑦⑧|
□⑤②②   |②--|
③③①□   |③--|
□□□⑥   |④⑤⑥|
⑦⑤⑩⑥   |①②③|
③⑪□□   |④⑤⑥|
⑨□②⑧   |⑦⑧⑨|
①①④⑫   |⑩⑪⑫|
⑤⑤□□   |①②③|
④⑦③③   |④--|
□②②⑥   |⑤--|
①①□⑧   |⑥⑦⑧|
⑥⑥③③   |①②③|
□□⑤⑤   |④--|
④②②□   |⑤--|
①①⑦□   |⑥-⑦|
⑧□⑤⑤   |①②③|
①①⑦□   |④--|
□□④④   |⑤-|
③⑥□②   |⑥⑦⑧|
□⑤④⑤   |①-②|
②□⑥②   |-③-|
④①□③   |④-⑤|
③⑥①□   |-⑥-|
⑤⑦⑥⑥   |①②③|
③③□④   |④--|
⑤②②⑧   |⑤--|
□□①①   |⑥⑦⑧|
⑤□⑦□   |①②③|
③③⑥④   |④--|
⑥②②□   |⑤-⑥|
①①⑤⑦   |-⑦-|
③②□①   |①---|
②□□④   |②---|
□□③③   |③---|
①①④□   |④---|
③□□②   |①---|
②□②④   |②---|
④①□③   |③---|
①□□①   |④---|
□①①⑤   |①---|
④①□□   |--②-|
□①①③   |③-④-|
□①②□   |--⑤-|
①□□□   |①-②-|
□□②⑤   |③-④-|
③□□□   |⑤---|
④□□⑤   ||
①□①⑤   |①---|
②①□□   ||
□①□③   |②-③-|
□①④□   |④-⑤-|
④④③□   |①---|
□①①□   |②-③-|
②□□□   |④---|
□□□□   ||
□④□⑤   |①---|
□□①③   |--②-|
□①□①   |③-④-|
②①□①   |--⑤-|
□□□□   |①-②-|
□□④④   |--③-|
□②□□   |④---|
③□①□   ||
①□□⑦   |①-②-|
□⑥□□   |③-④-|
②□⑤③   |⑤-⑥-|
□⑧④①   |⑦-⑧-|
①①③□   |①-②|
①□③③   |-③-|
②②④④   |④--|
②□④④   ||
①□□□   |①---|
②□□④   |②---|
③□□□   |③---|
□⑤□□   |④-⑤-|
□①⑦□   |①---|
□□□⑥   |②-③-|
□□⑤②   |④-⑤-|
③□□④   |⑥-⑦-|
□□□□   |①---|
①□①□   ||
□①□□   ||
□①□□   ||
□□□□   ||
□□□□   ||
□□□□   ||
□□□□   ||

View File

@ -9,8 +9,22 @@ from . import data
def test_RorataJins_example() -> None:
"""This file has a #memo tag but actually uses mono-column formatting,
Here I just check that a friendlier error message is sent because there
is not much else I can to do here, the file is plain old wrong"""
with pytest.raises(SyntaxError, match="separator line"):
with resources.path(data, "RorataJin's example.txt") as p:
format_ = guess_format(p)
loader = LOADERS[format_]
_ = loader(p)
def test_Booths_of_Fighters_memo() -> None:
"""This file has 2 quirks my code did not anticipate :
- while it's in #memo2 format, it actually uses b= and t= commands
- the position and timing parts are separated by some less common
whitespace character"""
with resources.path(data, "Booths_of_Fighters_memo.txt") as p:
format_ = guess_format(p)
loader = LOADERS[format_]
_ = loader(p)