Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_subscript():
code = "data['test'] = 36"
assert py2js(code) == "data['test'] = 36"
code = "data[0] = 35"
assert py2js(code) == "data[0] = 35"
def test_binary():
code = 'value or 3'
assert py2js(code) == '(value || 3)'
code = 'value and 3'
assert py2js(code) == '(value && 3)'
code = 'value + 3'
assert py2js(code) == '(value + 3)'
code = 'value**3'
assert py2js(code) == '(Math.pow(value, 3))'
# Unsupported operator
code = 'value & x'
with pytest.raises(Py2JSSyntaxError):
py2js(code)
def test_unary():
code = 'not value'
assert py2js(code) == '!(value)'
code = '-value'
assert py2js(code) == '-value'
code = '+value'
assert py2js(code) == '+value'
def test_list():
code = '[True, 3, \'hello\']'
assert py2js(code) == '[true, 3, \'hello\']'
def test_subscript():
code = "data['test'] = 36"
assert py2js(code) == "data['test'] = 36"
code = "data[0] = 35"
assert py2js(code) == "data[0] = 35"
def test_ternary():
code = '3 if value else 4'
assert py2js(code) == '(value ? 3 : 4)'
def test_unary():
code = 'not value'
assert py2js(code) == '!(value)'
code = '-value'
assert py2js(code) == '-value'
code = '+value'
assert py2js(code) == '+value'
code = 'value or 3'
assert py2js(code) == '(value || 3)'
code = 'value and 3'
assert py2js(code) == '(value && 3)'
code = 'value + 3'
assert py2js(code) == '(value + 3)'
code = 'value**3'
assert py2js(code) == '(Math.pow(value, 3))'
# Unsupported operator
code = 'value & x'
with pytest.raises(Py2JSSyntaxError):
py2js(code)
def test_num():
code = '36'
assert py2js(code) == '36'
def test_compare():
code = '3 < value <= 4'
assert py2js(code) == '(3 < value <= 4)'