       import Kernel, except: [-: 2]
       import Kernel.ExpansionTarget
 
-      assert expand(quote do: <<x::seventeen>>) ==
-             quote do: (<<x()::integer()-size(17)>>)
-
-      assert expand(quote do: (<<seventeen::seventeen, x::size(seventeen)>> = 1)) ==
-             quote do: (<<seventeen::integer()-size(17), x::integer()-size(seventeen)>> = 1)
+      assert expand(quote(do: <<x::seventeen>>)) == quote(do: <<x()::integer()-size(17)>>)
+
+      assert expand(quote(do: <<seventeen::seventeen, x::size(seventeen)>> = 1)) ==
+               quote(do: <<seventeen::integer()-size(17), x::integer()-size(seventeen)>> = 1)
     end
 
     test "expands macro in args" do
       import Kernel, except: [-: 2]
 
-      assert expand(quote do: (require Kernel.ExpansionTarget; <<x::size(Kernel.ExpansionTarget.seventeen)>>)) ==
-             quote do: (:"Elixir.Kernel.ExpansionTarget"; <<x()::integer()-size(17)>>)
+      before_expansion =
+        quote do
+          require Kernel.ExpansionTarget
+          <<x::size(Kernel.ExpansionTarget.seventeen())>>
+        end
+
+      after_expansion =
+        quote do
+          :"Elixir.Kernel.ExpansionTarget"
+          <<x()::integer()-size(17)>>
+        end
+
+      assert expand(before_expansion) == after_expansion
     end
 
     test "supports dynamic size" do
       import Kernel, except: [-: 2]
-      assert expand(quote do: (var = 1; <<x::size(var)-unit(8)>>)) ==
-             quote do: (var = 1; <<x()::integer()-unit(8)-size(var)>>)
+
+      before_expansion =
+        quote do
+          var = 1
+          <<x::size(var)-unit(8)>>
+        end
+
+      after_expansion =
+        quote do
+          var = 1
+          <<x()::integer()-unit(8)-size(var)>>
+        end
+
+      assert expand(before_expansion) == after_expansion
     end
 
     test "raises on size or unit for literal bitstrings" do
-      assert_raise CompileError, ~r"literal <<>> in bitstring supports only type specifiers", fn ->
-        expand(quote do: << <<"foo">>::32 >>)
+      message = ~r"literal <<>> in bitstring supports only type specifiers"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<(<<"foo">>::32)>>))
       end
     end
 
     test "raises on size or unit for literal strings" do
-      assert_raise CompileError, ~r"literal string in bitstring supports only endianness and type specifiers", fn ->
-        expand(quote do: <<"foo"::32>>)
+      message = ~r"literal string in bitstring supports only endianness and type specifiers"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<"foo"::32>>))
       end
     end
 
     test "raises for invalid size * unit for floats" do
-      assert_raise CompileError, ~r"float requires size\*unit to be 32 or 64 \(default\), got: 128", fn ->
-        expand(quote do: <<12.3::32*4>>)
-      end
-
-      assert_raise CompileError, ~r"float requires size\*unit to be 32 or 64 \(default\), got: 256", fn ->
-        expand(quote do: <<12.3::256>>)
+      message = ~r"float requires size\*unit to be 32 or 64 \(default\), got: 128"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<12.3::32*4>>))
+      end
+
+      message = ~r"float requires size\*unit to be 32 or 64 \(default\), got: 256"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<12.3::256>>))
       end
     end
 
     test "raises for invalid size" do
-      assert_raise CompileError, ~r"size in bitstring expects an integer or a variable as argument, got: :oops", fn ->
-        expand(quote do: <<"foo"::size(:oops)>>)
+      message = ~r"size in bitstring expects an integer or a variable as argument, got: :oops"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<"foo"::size(:oops)>>))
       end
     end
 
     test "raises for invalid unit" do
-      assert_raise CompileError, ~r"unit in bitstring expects an integer as argument, got: :oops", fn ->
-        expand(quote do: <<"foo"::size(8)-unit(:oops)>>)
+      message = ~r"unit in bitstring expects an integer as argument, got: :oops"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<"foo"::size(8)-unit(:oops)>>))
       end
     end
 
     test "raises for unknown specifier" do
       assert_raise CompileError, ~r"unknown bitstring specifier: unknown()", fn ->
-        expand(quote do: <<1::unknown>>)
+        expand(quote(do: <<1::unknown>>))
       end
     end
 
     test "raises for conflicting specifiers" do
       assert_raise CompileError, ~r"conflicting endianness specification for bit field", fn ->
-        expand(quote do: <<1::little-big>>)
+        expand(quote(do: <<1::little-big>>))
       end
 
       assert_raise CompileError, ~r"conflicting unit specification for bit field", fn ->
-        expand(quote do: <<x::bitstring-unit(2)>>)
+        expand(quote(do: <<x::bitstring-unit(2)>>))
       end
     end
 
     test "raises for invalid literals" do
       assert_raise CompileError, ~r"invalid literal :foo in <<>>", fn ->
-        expand(quote do: <<:foo>>)
+        expand(quote(do: <<:foo>>))
       end
 
       assert_raise CompileError, ~r"invalid literal \[\] in <<>>", fn ->
-        expand(quote do: <<[]::size(8)>>)
+        expand(quote(do: <<[]::size(8)>>))
       end
     end
 
     test "raises on binary fields with size in matches" do
-      assert expand(quote do: (<<x::binary-size(3), y::binary>> = "foobar"))
-
-      assert_raise CompileError,
-        ~r"a binary field without size is only allowed at the end of a binary pattern",
-        fn -> expand(quote do: (<<x::binary, y::binary>> = "foobar")) end
+      assert expand(quote(do: <<x::binary-size(3), y::binary>> = "foobar"))
+
+      message = ~r"a binary field without size is only allowed at the end of a binary pattern"
+
+      assert_raise CompileError, message, fn ->
+        expand(quote(do: <<x::binary, y::binary>> = "foobar"))
+      end
     end
   end
 
   describe "op ambiguity" do
     test "raises when a call is ambiguous" do
       message = ~r["a -1" looks like a function call but there is a variable named "a"]
-      assert_raise CompileError, message, fn ->
-        expand(quote do: (a = 1; a -1))
+
+      assert_raise CompileError, message, fn ->
+        # We use string_to_quoted! here to avoid the formatter adding parentheses to "a -1".
+        code =
+          Code.string_to_quoted!("""
+          a = 1
+          a -1
+          """)
+
+        expand(code)
       end
     end
   end
 
   test "handles invalid expressions" do
     assert_raise CompileError, ~r"invalid quoted expression: {1, 2, 3}", fn ->
-      expand(quote do: unquote({1, 2, 3}))
+      expand(quote(do: unquote({1, 2, 3})))
     end
 
     assert_raise CompileError, ~r"invalid quoted expression: #Function<", fn ->
-      expand(quote do: unquote({:sample, fn -> nil end}))
+      expand(quote(do: unquote({:sample, fn -> nil end})))
     end
 
     assert_raise CompileError, ~r"invalid pattern in match", fn ->
-      expand(quote do
-        case true do
-          true && true -> true
-        end
-      end)
+      code =
+        quote do
+          case true do
+            true && true -> true
+          end
+        end
+
+      expand(code)
     end
 
     assert_raise CompileError, ~r"invalid pattern in match", fn ->
-      expand(quote do
-        x = &(&1)
-        case true do
-          x.(false) -> true
-        end
-      end)
+      code =
+        quote do
+          x = & &1
+
+          case true do
+            x.(false) -> true
+          end
+        end
+
+      expand(code)
     end
 
     assert_raise CompileError, ~r"invalid expression in guard", fn ->
-      expand(quote do
-        x = &(&1)
-        case true do
-          true when x.(true) -> true
-        end
-      end)
+      code =
+        quote do
+          x = & &1
+
+          case true do
+            true when x.(true) -> true
+          end
+        end
+
+      expand(code)
     end
 
     assert_raise CompileError, ~r"invalid call foo\(1\)\(2\)", fn ->
-      expand(quote do: foo(1)(2))
+      expand(quote(do: foo(1)(2)))
     end
 
     assert_raise CompileError, ~r"invalid call 1\.foo\(\)", fn ->
-      expand(quote do: 1.foo)
+      expand(quote(do: 1.foo))
     end
 
     assert_raise CompileError, ~r"unhandled operator ->", fn ->
-      expand(quote do: (foo -> bar))
-    end
-
-    assert_raise CompileError,
-      ~r"size in bitstring expects an integer or a variable as argument, got: foo\(\)",
-      fn ->
-        expand(quote do
+      expand(quote(do: (foo -> bar)))
+    end
+
+    message = ~r"size in bitstring expects an integer or a variable as argument, got: foo\(\)"
+
+    assert_raise CompileError, message, fn ->
+      code =
+        quote do
           fn <<_::size(foo)>> -> :ok end
-        end)
-      end
+        end
+
+      expand(code)
+    end
   end
 
   ## Helpers

  describe "require" do
    test "raises for non-compile-time module" do
      assert_raise CompileError, ~r"invalid argument for require, .*, got: {:a, :tuple}", fn ->
        expand(quote do: (require {:a, :tuple}))
      end
    end

    test "invalid options" do
      assert_raise CompileError, ~r"unsupported option :ops given to require", fn ->
        expand(quote do: (require Foo, ops: 1))
      end
    end
  end

  describe "=" do
    test "sets context to match" do
      assert expand(quote do: __ENV__.context = :match) == quote do: :match = :match
    end

    test "defines vars" do

    test "expand args, defines alias and returns itself" do
      alias true, as: True

      input = quote(do: alias(:hello, as: World, warn: True))
      {output, env} = expand_env(input, __ENV__)

      assert output == :hello
