"""EST 테스트 앱 단가산출 전역변수(원본 \x05 표지 — 호표를 넘어 값 유지, 지정·해제, 목록).""" import json import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[2] def test_global_variable_crosses_groups_and_toggle(): code = r""" const fs = require('fs'), vm = require('vm'); const ctx = vm.createContext({ structuredClone }); for (const f of ['native-math.js', 'native-formula.js', 'native-text.js', 'native-global-vars.js']) vm.runInContext(fs.readFileSync('tools/est-test/' + f, 'utf8'), ctx, { filename: f }); const T = vm.runInContext('EstText', ctx), G = vm.runInContext('EstGlobalVars', ctx); const rows = [ { Index: 1, Code: 'D1', LineData: '호표1' }, { Index: 0, SCheck: 0, LineData: '\x05Q\x05 = 2 × 3 = \x126\x12' }, { Index: 1, Code: 'D2', LineData: '호표2' }, { Index: 0, SCheck: -1, LineData: '노무 = Q × 10 = \x120\x12' }, { Index: 1, Code: 'D3', LineData: '호표3' }, { Index: 0, SCheck: 0, LineData: 'R = 1 = \x121\x12' }, { Index: 1, Code: 'D4', LineData: '호표4' }, { Index: 0, SCheck: -1, LineData: '노무 = R × 10 = \x120\x12' }, ]; const r = T.calculate(rows, {}); let bad = ''; try { G.toggle('가 = 3', 0); } catch (e) { bad = e.message.slice(0, 12); } process.stdout.write(JSON.stringify({ used: r.rows[3].LineData.match(/\x12([^\x12]+)\x12/)[1], kept: r.rows[1].LineData.startsWith('\x05Q\x05'), local: r.errors.length, globals: r.globals, on: G.toggle('Q = 2', 0), off: G.toggle('⟦전역⟧Q⟦전역⟧ = 2', 5), bad, clean: T.clean('\x05Q\x05 = 1'), shown: T.display('\x05V1\x05'), back: T.encode('⟦전역⟧V1⟦전역⟧') === '\x05V1\x05', })); """ out = json.loads(subprocess.check_output(["node", "-e", code], cwd=ROOT).decode("utf-8")) assert out["used"] == "60" assert out["kept"] is True assert out["local"] == 1 # R 은 전역이 아니라 D4 에서 못 찾음 assert out["globals"] == [{"name": "Q", "value": 6, "index": 1}] assert out["on"] == "⟦전역⟧Q⟦전역⟧ = 2" assert out["off"] == "Q = 2" assert out["bad"] == "선택한 변수는 전역변수" assert out["clean"] == "Q = 1" assert out["shown"] == "⟦전역⟧V1⟦전역⟧" and out["back"] is True