Skip to content

Commit

Permalink
split test_set
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Jan 4, 2025
1 parent 509bb1e commit 94de564
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tests/unit/test_macros/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

@test_setup
class TestSet(MacroTestBase):
# `set` is also used in many other macro tests already, so there aren't many here.

async def test_set_key(self):
code_b = keyboard_layout.get("b")
macro = Parser.parse("set(foo, b).key($foo)", self.context, DummyMapping)
Expand All @@ -47,35 +45,48 @@ async def test_set_key(self):
],
)

async def test_set(self):
await Parser.parse(
'set(a, "foo")',
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("a"), "foo")

async def test_int_is_explicit_string(self):
await Parser.parse(
'set( \t"b" \n, "1")',
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("b"), "1")

async def test_int_is_int(self):
await Parser.parse(
"set(a, 1)",
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("a"), 1)

async def test_none(self):
await Parser.parse(
"set(a, )",
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("a"), None)

async def test_set_case_sensitive_1(self):
await Parser.parse(
'set(a, "foo")',
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("a"), "foo")
self.assertEqual(macro_variables.get("A"), None)

async def test_set_case_sensitive_2(self):
await Parser.parse(
'set(A, "foo")',
self.context,
DummyMapping,
).run(self.handler)
self.assertEqual(macro_variables.get("A"), "foo")
self.assertEqual(macro_variables.get("a"), None)

async def test_raises_error(self):
self.assertRaises(MacroError, Parser.parse, "set($a, 1)", self.context)
self.assertRaises(MacroError, Parser.parse, "set(1, 2)", self.context)
Expand Down

0 comments on commit 94de564

Please sign in to comment.