about summary refs log tree commit diff stats
path: root/js/baba-yaga/web/editor/test-formatter.html
blob: 616afe2c3e5c05c6859041fa09827aaab1123db4 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Baba Yaga Formatter</title>
    <style>
        body {
            font-family: monospace;
            padding: 20px;
            background: #1e1e1e;
            color: #d4d4d4;
        }
        .test-section {
            margin: 20px 0;
            padding: 20px;
            border: 1px solid #3e3e42;
            border-radius: 8px;
        }
        .code-block {
            background: #2d2d30;
            padding: 10px;
            border-radius: 4px;
            white-space: pre-wrap;
            margin: 10px 0;
        }
        .success { color: #4ec9b0; }
        .error { color: #f14c4c; }
        button {
            background: #007acc;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 10px 0;
        }
        button:hover {
            background: #005a9e;
        }
    </style>
</head>
<body>
    <h1>Baba Yaga Formatter Test</h1>
    
    <div class="test-section">
        <h2>Test 1: Basic Function Formatting</h2>
        <div class="code-block" id="input1">add:x y->x+y;</div>
        <button onclick="testFormat1()">Format Test 1</button>
        <div class="code-block" id="output1"></div>
        <div id="result1"></div>
    </div>

    <div class="test-section">
        <h2>Test 2: Complex Code Formatting</h2>
        <div class="code-block" id="input2">factorial:n->when n is 0 then 1 1 then 1 _ then n*factorial(n-1);</div>
        <button onclick="testFormat2()">Format Test 2</button>
        <div class="code-block" id="output2"></div>
        <div id="result2"></div>
    </div>

    <div class="test-section">
        <h2>Test 3: Multiple Functions</h2>
        <div class="code-block" id="input3">add:x y->x+y;
multiply:x y->x*y;
result:add 5 3;</div>
        <button onclick="testFormat3()">Format Test 3</button>
        <div class="code-block" id="output3"></div>
        <div id="result3"></div>
    </div>

    <!-- Load Baba Yaga components -->
    <script type="module">
        import { createLexer, tokenTypes } from '../../lexer.js';
        import { createParser } from '../../parser.js';
        
        // Make them globally available
        window.createLexer = createLexer;
        window.createParser = createParser;
        window.tokenTypes = tokenTypes;
        
        console.log('Baba Yaga modules loaded');
    </script>

    <!-- Load formatter -->
    <script src="js/formatter.js"></script>

    <script>
        function testFormat1() {
            const input = document.getElementById('input1').textContent;
            const output = document.getElementById('output1');
            const result = document.getElementById('result1');
            
            try {
                const formatter = new BabaYagaFormatter();
                const formatted = formatter.format(input);
                output.textContent = formatted;
                result.innerHTML = '<span class="success">✓ Formatting successful!</span>';
            } catch (error) {
                output.textContent = 'Error: ' + error.message;
                result.innerHTML = '<span class="error">✗ Formatting failed: ' + error.message + '</span>';
            }
        }

        function testFormat2() {
            const input = document.getElementById('input2').textContent;
            const output = document.getElementById('output2');
            const result = document.getElementById('result2');
            
            try {
                const formatter = new BabaYagaFormatter();
                const formatted = formatter.format(input);
                output.textContent = formatted;
                result.innerHTML = '<span class="success">✓ Formatting successful!</span>';
            } catch (error) {
                output.textContent = 'Error: ' + error.message;
                result.innerHTML = '<span class="error">✗ Formatting failed: ' + error.message + '</span>';
            }
        }

        function testFormat3() {
            const input = document.getElementById('input3').textContent;
            const output = document.getElementById('output3');
            const result = document.getElementById('result3');
            
            try {
                const formatter = new BabaYagaFormatter();
                const formatted = formatter.format(input);
                output.textContent = formatted;
                result.innerHTML = '<span class="success">✓ Formatting successful!</span>';
            } catch (error) {
                output.textContent = 'Error: ' + error.message;
                result.innerHTML = '<span class="error">✗ Formatting failed: ' + error.message + '</span>';
            }
        }

        // Test formatter availability on load
        window.addEventListener('load', () => {
            setTimeout(() => {
                if (typeof BabaYagaFormatter !== 'undefined') {
                    console.log('✓ BabaYagaFormatter is available');
                } else {
                    console.error('✗ BabaYagaFormatter is not available');
                }
                
                if (typeof createLexer !== 'undefined' && typeof createParser !== 'undefined') {
                    console.log('✓ Baba Yaga language components are available');
                } else {
                    console.error('✗ Baba Yaga language components are not available');
                }
            }, 1000);
        });
    </script>
</body>
</html>