import unittest
import fasm


def check_round_trip(test, result):
    s = fasm.fasm_tuple_to_string(result)
    test.assertEqual(list(fasm.parse_fasm_string(s)), result)


class TestFasm(unittest.TestCase):
    def test_blank_file(self):
        result = list(fasm.parse_fasm_filename('fasm_blank.fasm'))
        self.assertEqual(result, [])

        check_round_trip(self, result)

    def test_comment_file(self):
        result = list(fasm.parse_fasm_filename('fasm_comment.fasm'))
        self.assertEqual(
            result, [
                fasm.FasmLine(
                    set_feature=None,
                    annotations=None,
                    comment=' Only a comment.',
                )
            ])

        check_round_trip(self, result)

    def test_one_line_feature(self):
        result = list(fasm.parse_fasm_filename('fasm_feature_only.fasm'))
        self.assertEqual(
            result, [
                fasm.FasmLine(
                    set_feature=fasm.SetFasmFeature(
                        feature='EXAMPLE_FEATURE.X0.Y0.BLAH',
                        start=None,
                        end=None,
                        value=1,
                        value_format=None,
                    ),
                    annotations=None,
                    comment=None,
                )
            ])

        self.assertEqual(
            fasm.fasm_tuple_to_string(result), 'EXAMPLE_FEATURE.X0.Y0.BLAH\n')
        check_round_trip(self, result)

    def test_examples_file(self):
        result = list(fasm.parse_fasm_filename('fasm_examples.fasm'))
        check_round_trip(self, result)


if __name__ == '__main__':
    unittest.main()

@@ -1,31 +1,178 @@
-import unittest%0Aimport fasm
+#!/usr/bin/env python3%0Aimport os%0Aimport os.path%0A%0Aimport unittest%0Aimport fasm%0A%0A%0Adef example(fname):%0A    return os.path.join(os.path.dirname(__file__), '..', 'examples', fname)
 %0A%0A%0Ad
@@ -425,22 +425,25 @@
 ilename(
-'fasm_
+example('
 blank.fa
@@ -439,32 +439,33 @@
 e('blank.fasm'))
+)
 %0A        self.as
@@ -607,22 +607,25 @@
 ilename(
-'fasm_
+example('
 comment.
@@ -623,32 +623,33 @@
 'comment.fasm'))
+)
 %0A        self.as
@@ -994,22 +994,25 @@
 ilename(
-'fasm_
+example('
 feature_
@@ -1015,32 +1015,33 @@
 ure_only.fasm'))
+)
 %0A        self.as
@@ -1724,30 +1724,29 @@
 ame(
-'fasm_
 example
-s
+('many
 .fasm'))
 %0A   
@@ -1741,16 +1741,17 @@
 .fasm'))
+)
 %0A       

Fix test tests.