Files @ 831e30606026
Branch filter:

Location: Jasinta/tests/test_jasinta.py

Laman
implemented the String object
from unittest import TestCase
from unittest.mock import patch

from pyjsparser import parse

from jasinta import interpret


class TestBasics(TestCase):
	@patch("builtins.print")
	def test_addition(self, mock_print):
		s = """var a=3;
var b=1;
var c=a+b;
document.write(c);"""

		interpret(parse(s))
		mock_print.assert_called_with(4)

	@patch("builtins.print")
	def test_assignment(self, mock_print):
		s = """var a=1;
var b=1;
a+=b;
b+=a;
document.write(b);"""

		interpret(parse(s))
		mock_print.assert_called_with(3)


class TestString(TestCase):
	@patch("builtins.print")
	def test_assignment(self, mock_print):
		s = """var s = "abcdefgh";
var a = s.charAt(0);
var bcd = s.slice(1, 4);
var efg = s.substr(4, 3);
var h = String.fromCharCode(104);
document.cookie = a+bcd+efg+h;
document.write(document.cookie);"""

		interpret(parse(s))
		mock_print.assert_called_with("abcdefgh")