File size: 1,276 Bytes
25693a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Offline tests for rejecting source changes the exporter cannot safely parse."""
import unittest

from export import parse_source

HEADER = "import Mathlib\n\nset_option maxHeartbeats 0\n\nopen BigOperators Real Nat Topology Rat\n\n"
SOURCE = (HEADER + "theorem example_1 (n : ℕ) : n = n := by sorry\n").encode("utf-8")


class ParseSourceTest(unittest.TestCase):
    def test_preserves_unicode_and_exact_source(self):
        row = parse_source("MiniF2F/Test/example_1.lean", SOURCE)
        self.assertEqual((row["header"] + row["formal_statement"]).encode("utf-8"), SOURCE)
        self.assertEqual(row["id"], "example_1")

    def test_rejects_ambiguous_or_changed_source(self):
        mutations = [
            SOURCE.replace(b"by sorry", b"by rfl"),
            SOURCE + b"theorem second : True := by sorry\n",
            SOURCE.replace(b"n = n", b"n = (by sorry)"),
            SOURCE + b"#eval 1\n",
            SOURCE.replace(b"import Mathlib", b"import Other"),
            SOURCE.replace(b"example_1", b"different_name"),
        ]
        for source in mutations:
            with self.subTest(source=source), self.assertRaises(ValueError):
                parse_source("MiniF2F/Test/example_1.lean", source)


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