     assert "aa" =~ ~r/(a)\1/
   end
 
-  test "compile!" do
-    assert Regex.regex?(Regex.compile!("foo"))
-
-    assert_raise Regex.CompileError, ~r/position 0$/, fn ->
-      Regex.compile!("*foo")
-    end
-  end
-
-  test "compile" do
+  test "source" do
+    src = "foo"
+    assert Regex.source(Regex.compile!(src)) == src
+    assert Regex.source(~r/#{src}/) == src
+
+    src = "\a\b\d\e\f\n\r\s\t\v"
+    assert Regex.source(Regex.compile!(src)) == src
+    assert Regex.source(~r/#{src}/) == src
+
+    src = "\a\\b\\d\\e\f\n\r\\s\t\v"
+    assert Regex.source(Regex.compile!(src)) == src
+    assert Regex.source(~r/#{src}/) == src
+  end
+
+  test "literal source" do
+    assert Regex.source(Regex.compile!("foo")) == "foo"
+    assert Regex.source(~r"foo") == "foo"
+    assert Regex.re_pattern(Regex.compile!("foo"))
+           == Regex.re_pattern(~r"foo")
+
+    assert Regex.source(Regex.compile!("\a\b\d\e\f\n\r\s\t\v")) == "\a\b\d\e\f\n\r\s\t\v"
+    assert Regex.source(~r<\a\b\d\e\f\n\r\s\t\v>) == "\a\\b\\d\\e\f\n\r\\s\t\v"
+    assert Regex.re_pattern(Regex.compile!("\a\b\d\e\f\n\r\s\t\v"))
+           == Regex.re_pattern(~r"\a\010\177\033\f\n\r \t\v")
+
+    assert Regex.source(Regex.compile!("\a\\b\\d\e\f\n\r\\s\t\v")) == "\a\\b\\d\e\f\n\r\\s\t\v"
+    assert Regex.source(~r<\a\\b\\d\\e\f\n\r\\s\t\v>) == "\a\\\\b\\\\d\\\\e\f\n\r\\\\s\t\v"
+    assert Regex.re_pattern(Regex.compile!("\a\\b\\d\e\f\n\r\\s\t\v"))
+           == Regex.re_pattern(~r"\a\b\d\e\f\n\r\s\t\v")
+  end
+
+  test "Unicode" do
+    assert "olá" =~ ~r"\p{Latin}$"u
+    refute "£" =~ ~r/\p{Lu}/u
+
+    # Non breaking space matches [[:space:]] with Unicode
+    assert <<0xA0::utf8>> =~ ~r/[[:space:]]/u
+    assert <<0xA0::utf8>> =~ ~r/\s/u
+
+    assert <<?<, 255, ?>>> =~ ~r/<.>/
+    refute <<?<, 255, ?>>> =~ ~r/<.>/u
+  end
+
+  test "ungreedy" do
+    assert Regex.run(~r/[\d ]+/, "1 2 3 4 5"), ["1 2 3 4 5"]
+    assert Regex.run(~r/[\d ]?+/, "1 2 3 4 5"), ["1"]
+    assert Regex.run(~r/[\d ]+/U, "1 2 3 4 5"), ["1"]
+  end
+
+  test "regex?/1" do
+    assert Regex.regex?(~r/foo/)
+    refute Regex.regex?(0)
+  end
+
+  test "compile/1" do
     {:ok, regex} = Regex.compile("foo")
     assert Regex.regex?(regex)
     assert {:error, _} = Regex.compile("*foo")

    assert Regex.match?(~r/foo$/,  "afoo")
  end

  test "named captures" do
    assert Regex.named_captures(~r/(?<foo>c)(?<bar>d)/, "abcd") == %{"bar" => "d", "foo" => "c"}
    assert Regex.named_captures(~r/c(?<foo>d)/, "abcd") == %{"foo" => "d"}
    assert Regex.named_captures(~r/c(?<foo>d)/, "no_match") == nil

    assert Regex.replace(~r[a(b)c], "abcabc", fn "abc", "b" -> "ac" end, global: false) == "acabc"
  end

  test "escape" do
    assert matches_escaped?(".")
    refute matches_escaped?(".", "x")
