diff --git a/src/tja2fumen/parsers.py b/src/tja2fumen/parsers.py index 9aacaa3..0049bdd 100644 --- a/src/tja2fumen/parsers.py +++ b/src/tja2fumen/parsers.py @@ -52,13 +52,15 @@ def split_tja_lines_into_courses(lines): # Course-specific header fields elif name_upper == 'COURSE': + if value not in NORMALIZE_COURSE.keys(): + raise ValueError(f"Invalid COURSE value: '{value}'") current_course = NORMALIZE_COURSE[value] current_course_cached = current_course - if current_course not in parsed_tja.courses.keys(): - raise ValueError() elif name_upper == 'LEVEL': - parsed_tja.courses[current_course].level = \ - int(value) if value else 0 + if value not in ['1', '2', '3', '4', '5', + '6', '7', '8', '9', '10']: + raise ValueError(f"Invalid LEVEL value: '{value}") + parsed_tja.courses[current_course].level = int(value) elif name_upper == 'SCOREINIT': parsed_tja.courses[current_course].score_init = \ int(value.split(",")[-1]) if value else 0 diff --git a/testing/data/dummy_tjas/missing_course.tja b/testing/data/dummy_tjas/missing_course.tja new file mode 100644 index 0000000..78ac3a3 --- /dev/null +++ b/testing/data/dummy_tjas/missing_course.tja @@ -0,0 +1,17 @@ +// This song contains only basic notes. +BPM:120 +OFFSET:-1.00 + +COURSE: +LEVEL:10 +BALLOON:8,8 +SCOREINIT:400 +SCOREDIFF:100 + +#START +1020304, +5000008, +6000008, +7000008, +9000008, +#END diff --git a/testing/data/dummy_tjas/missing_level.tja b/testing/data/dummy_tjas/missing_level.tja new file mode 100644 index 0000000..46dee92 --- /dev/null +++ b/testing/data/dummy_tjas/missing_level.tja @@ -0,0 +1,17 @@ +// This song contains only basic notes. +BPM:120 +OFFSET:-1.00 + +COURSE:Oni +LEVEL: +BALLOON:8,8 +SCOREINIT:400 +SCOREDIFF:100 + +#START +1020304, +5000008, +6000008, +7000008, +9000008, +#END diff --git a/testing/data/dummy_tjas/missing_score.tja b/testing/data/dummy_tjas/missing_score.tja new file mode 100644 index 0000000..e15349d --- /dev/null +++ b/testing/data/dummy_tjas/missing_score.tja @@ -0,0 +1,17 @@ +// This song is missing `SCOREINIT:` and `SCOREDIFF:` metadata +BPM:120 +OFFSET:-1.00 + +COURSE:Oni +LEVEL:10 +BALLOON:8,8 +SCOREINIT: +SCOREDIFF: + +#START +1020304, +5000008, +6000008, +7000008, +9000008, +#END diff --git a/testing/test_command_support.py b/testing/test_command_support.py index 7af7d07..7943867 100644 --- a/testing/test_command_support.py +++ b/testing/test_command_support.py @@ -8,7 +8,10 @@ from conftest import convert @pytest.mark.parametrize('id_song,err_msg', [ ['basic_song', None], - ['missing_balloon', "Not enough values for 'BALLOON:"] + ['missing_score', None], + ['missing_balloon', "Not enough values for 'BALLOON:"], + ['missing_course', "Invalid COURSE value:"], + ['missing_level', "Invalid LEVEL value:"] ]) def test_expected_errors(id_song, err_msg, tmp_path, entry_point): # Define the testing directory