File: test_statements.py

package info (click to toggle)
pcbasic 2.0.7-8
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 35,416 kB
  • sloc: python: 28,411; sh: 103; makefile: 10
file content (56 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (2)
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
"""
PC-BASIC test.statements
unit tests for PC-BASIC specific behaviour of statements

(c) 2022--2023 Rob Hagemans
This file is released under the GNU GPL version 3 or later.
"""

from io import BytesIO
from tempfile import NamedTemporaryFile

from pcbasic import Session
from tests.unit.utils import TestCase, run_tests


class StatementTest(TestCase):
    """Unit tests for statements."""

    tag = u'statements'

    def test_llist(self):
        """Test LLIST to stream."""
        with NamedTemporaryFile(delete=False) as output:
            with Session(devices={'lpt1': 'FILE:'+output.name}) as s:
                s.execute("""
                    10 rem program
                    20?1
                """)
                s.execute('LLIST')
            outstr = output.read()
            assert outstr == b'10 REM program\r\n20 PRINT 1\r\n', outstr

    def test_cls_pcjr(self):
        """Test CLS syntax on pcjr."""
        with Session(syntax='pcjr') as s:
            s.execute('CLS')
            assert self.get_text_stripped(s)[0] == b''
            s.execute('CLS 0')
            assert self.get_text_stripped(s)[0] == b'Syntax error\xFF'
            s.execute('CLS 0,')
            assert self.get_text_stripped(s)[0] == b'Syntax error\xFF'
            s.execute('CLS ,')
            assert self.get_text_stripped(s)[0] == b'Syntax error\xFF'

    def test_wait(self):
        """Test WAIT syntax."""
        with Session(syntax='pcjr') as s:
            s.execute('')
            s._impl.keyboard.last_scancode = 255
            s.execute('wait &h60, 255')
            s._impl.keyboard.last_scancode = 0
            s.execute('wait &h60, 255, 255')
            assert self.get_text_stripped(s)[0] == b''

if __name__ == '__main__':
    run_tests()