summaryrefslogtreecommitdiff
path: root/tests/test_lexer.py
blob: 1d7f8e7788306382c69c2b84898f7c33e41e6b7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""Tests for the MML lexer."""

from mml_composemusic_mcp.lexer import TokenType, tokenize


def test_ppmck_tokens():
    source = "A t150 l8 o4 v15 @2\nc d e f"
    tokens = tokenize(source, "ppmck")
    types = [t.type for t in tokens]
    assert TokenType.TRACK_HEADER in types
    assert TokenType.TEMPO in types
    assert TokenType.NOTE in types
    assert TokenType.DUTY in types


def test_pyxel_tokens():
    source = "0: T150 L8 O4 V100 @1\nC D E F"
    tokens = tokenize(source, "pyxel")
    types = [t.type for t in tokens]
    assert TokenType.TRACK_HEADER in types
    assert TokenType.AT in types
    assert TokenType.NOTE in types


def test_pyxel_repeat():
    tokens = tokenize("[ C D ]2", "pyxel")
    assert any(t.type == TokenType.REPEAT_START for t in tokens)
    assert any(t.type == TokenType.REPEAT_END for t in tokens)


def test_ppmck_invalid_token():
    tokens = tokenize("A t120 l4 o4 x c", "ppmck")
    assert any(t.type == TokenType.INVALID for t in tokens)


def test_pyxel_invalid_token():
    tokens = tokenize("0: T120 L4 O4 X C", "pyxel")
    assert any(t.type == TokenType.INVALID for t in tokens)


def test_ppmck_at_duty():
    tokens = tokenize("A @2 c", "ppmck")
    assert any(t.type == TokenType.DUTY for t in tokens)


def test_ppmck_quantize():
    tokens = tokenize("A q4 c", "ppmck")
    assert any(t.type == TokenType.QUANTIZE for t in tokens)


def test_ppmck_tie_cmd():
    tokens = tokenize("A c4 ^4", "ppmck")
    assert any(t.type == TokenType.TIE_CMD for t in tokens)


def test_ppmck_detune():
    tokens = tokenize("A D10 c", "ppmck")
    assert any(t.type == TokenType.DETUNE for t in tokens)


def test_ppmck_sweep():
    tokens = tokenize("A s1,2 c", "ppmck")
    assert any(t.type == TokenType.SWEEP for t in tokens)


def test_ppmck_rel_vol():
    tokens = tokenize("A v+5 v-3 c", "ppmck")
    assert any(t.type == TokenType.REL_VOL_UP for t in tokens)
    assert any(t.type == TokenType.REL_VOL_DOWN for t in tokens)


def test_ppmck_vol_env():
    tokens = tokenize("A @v0 c", "ppmck")
    assert any(t.type == TokenType.VOL_ENV for t in tokens)


def test_ppmck_vol_env_def():
    tokens = tokenize("@v0 = { 15, 10, | 5 }", "ppmck")
    assert any(t.type == TokenType.VOL_ENV for t in tokens)
    assert any(t.type == TokenType.BRACE_OPEN for t in tokens)
    assert any(t.type == TokenType.BRACE_CLOSE for t in tokens)


def test_ppmck_lfo_def():
    tokens = tokenize("@MP0 = { 0, 10, 5, 0 }", "ppmck")
    assert any(t.type == TokenType.LFO_DEF for t in tokens)


def test_ppmck_lfo_use_off():
    tokens = tokenize("A MP1 MPOF c", "ppmck")
    assert any(t.type == TokenType.LFO_USE for t in tokens)
    assert any(t.type == TokenType.LFO_OFF for t in tokens)


def test_ppmck_pitch_env():
    tokens = tokenize("A EP1 EPOF c", "ppmck")
    assert any(t.type == TokenType.PITCH_ENV_USE for t in tokens)
    assert any(t.type == TokenType.PITCH_ENV_OFF for t in tokens)


def test_ppmck_note_env():
    tokens = tokenize("A EN1 ENOF c", "ppmck")
    assert any(t.type == TokenType.NOTE_ENV_USE for t in tokens)
    assert any(t.type == TokenType.NOTE_ENV_OFF for t in tokens)


def test_ppmck_duty_env_use():
    tokens = tokenize("A @@0 c", "ppmck")
    assert any(t.type == TokenType.DUTY_ENV_USE for t in tokens)