From 5f149826e10560afd41216a7daf702f6afe3933f Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Mon, 16 May 2016 18:43:22 -0500 Subject: [PATCH 1/3] Rename existing koans to make room for sigils --- lib/koans/{03_atoms.ex => 04_atoms.ex} | 0 lib/koans/{04_tuples.ex => 05_tuples.ex} | 0 lib/koans/{05_lists.ex => 06_lists.ex} | 0 lib/koans/{06_keyword_lists.ex => 07_keyword_lists.ex} | 0 lib/koans/{07_maps.ex => 08_maps.ex} | 0 lib/koans/{08_structs.ex => 09_structs.ex} | 0 lib/koans/{09_pattern_matching.ex => 10_pattern_matching.ex} | 0 lib/koans/{10_functions.ex => 11_functions.ex} | 0 lib/koans/{11_enums.ex => 12_enums.ex} | 0 lib/koans/{12_processes.ex => 13_processes.ex} | 0 lib/koans/{13_tasks.ex => 14_tasks.ex} | 0 lib/koans/{14_agents.ex => 15_agents.ex} | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename lib/koans/{03_atoms.ex => 04_atoms.ex} (100%) rename lib/koans/{04_tuples.ex => 05_tuples.ex} (100%) rename lib/koans/{05_lists.ex => 06_lists.ex} (100%) rename lib/koans/{06_keyword_lists.ex => 07_keyword_lists.ex} (100%) rename lib/koans/{07_maps.ex => 08_maps.ex} (100%) rename lib/koans/{08_structs.ex => 09_structs.ex} (100%) rename lib/koans/{09_pattern_matching.ex => 10_pattern_matching.ex} (100%) rename lib/koans/{10_functions.ex => 11_functions.ex} (100%) rename lib/koans/{11_enums.ex => 12_enums.ex} (100%) rename lib/koans/{12_processes.ex => 13_processes.ex} (100%) rename lib/koans/{13_tasks.ex => 14_tasks.ex} (100%) rename lib/koans/{14_agents.ex => 15_agents.ex} (100%) diff --git a/lib/koans/03_atoms.ex b/lib/koans/04_atoms.ex similarity index 100% rename from lib/koans/03_atoms.ex rename to lib/koans/04_atoms.ex diff --git a/lib/koans/04_tuples.ex b/lib/koans/05_tuples.ex similarity index 100% rename from lib/koans/04_tuples.ex rename to lib/koans/05_tuples.ex diff --git a/lib/koans/05_lists.ex b/lib/koans/06_lists.ex similarity index 100% rename from lib/koans/05_lists.ex rename to lib/koans/06_lists.ex diff --git a/lib/koans/06_keyword_lists.ex b/lib/koans/07_keyword_lists.ex similarity index 100% rename from lib/koans/06_keyword_lists.ex rename to lib/koans/07_keyword_lists.ex diff --git a/lib/koans/07_maps.ex b/lib/koans/08_maps.ex similarity index 100% rename from lib/koans/07_maps.ex rename to lib/koans/08_maps.ex diff --git a/lib/koans/08_structs.ex b/lib/koans/09_structs.ex similarity index 100% rename from lib/koans/08_structs.ex rename to lib/koans/09_structs.ex diff --git a/lib/koans/09_pattern_matching.ex b/lib/koans/10_pattern_matching.ex similarity index 100% rename from lib/koans/09_pattern_matching.ex rename to lib/koans/10_pattern_matching.ex diff --git a/lib/koans/10_functions.ex b/lib/koans/11_functions.ex similarity index 100% rename from lib/koans/10_functions.ex rename to lib/koans/11_functions.ex diff --git a/lib/koans/11_enums.ex b/lib/koans/12_enums.ex similarity index 100% rename from lib/koans/11_enums.ex rename to lib/koans/12_enums.ex diff --git a/lib/koans/12_processes.ex b/lib/koans/13_processes.ex similarity index 100% rename from lib/koans/12_processes.ex rename to lib/koans/13_processes.ex diff --git a/lib/koans/13_tasks.ex b/lib/koans/14_tasks.ex similarity index 100% rename from lib/koans/13_tasks.ex rename to lib/koans/14_tasks.ex diff --git a/lib/koans/14_agents.ex b/lib/koans/15_agents.ex similarity index 100% rename from lib/koans/14_agents.ex rename to lib/koans/15_agents.ex From 649c649084f57a639238d02f9ec120d94905d7d0 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Mon, 16 May 2016 18:43:45 -0500 Subject: [PATCH 2/3] Port sigil koans from iamvery/elixir-koans https://github.com/iamvery/elixir-koans/blob/7705d743acf3720f75852eb6badfe57f428a3481/about_sigils.exs h/t @sebastiangeiger --- lib/koans/03_sigils.ex | 39 ++++++++++++++++++++++++++++++++ test/koans/sigils_koans_test.exs | 19 ++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/koans/03_sigils.ex create mode 100644 test/koans/sigils_koans_test.exs diff --git a/lib/koans/03_sigils.ex b/lib/koans/03_sigils.ex new file mode 100644 index 0000000..9e72ad8 --- /dev/null +++ b/lib/koans/03_sigils.ex @@ -0,0 +1,39 @@ +defmodule Sigils do + use Koans + + @intro "Sigils" + + koan "The ~s sigil is a different way of expressing string literals" do + assert ~s{This is a string} == ___ + end + + koan "Sigils are useful to avoid escaping quotes in strings" do + assert "\"Welcome to the jungle\", they said." == ___ + end + + koan "Sigils can use different delimiters" do + matches? = ~s{This works!} == ~s[This works!] + assert matches? == ___ + end + + koan "The lowercase ~s sigil supports string interpolation" do + assert ~s[1 + 1 = #{1+1}] == ___ + end + + koan "The ~S sigil is similar to ~s but doesn't do interpolation" do + assert ~S[1 + 1 = #{1+1}] == ___ + end + + koan "The ~w sigil creates word lists" do + assert ~w(Hello world) == [___, ___] + end + + koan "The ~w sigil also allows interpolation" do + assert ~w(Hello 1#{1+1}3) == [___, ___] + end + + koan "The ~W sigil behaves to ~w as ~S behaves to ~s" do + assert ~W(Hello #{1+1}) == ["Hello", ___] + end +end + diff --git a/test/koans/sigils_koans_test.exs b/test/koans/sigils_koans_test.exs new file mode 100644 index 0000000..0821eaa --- /dev/null +++ b/test/koans/sigils_koans_test.exs @@ -0,0 +1,19 @@ +defmodule SigilsTests do + use ExUnit.Case + import TestHarness + + test "Sigils" do + answers = [ + "This is a string", + ~S("Welcome to the jungle", they said.), + true, + "1 + 1 = 2", + ~S(1 + 1 = #{1+1}), + {:multiple, ["Hello", "world"]}, + {:multiple, ["Hello", "123"]}, + ~S(#{1+1}), + ] + + test_all(Sigils, answers) + end +end From e60a284e36d978770fd2a0aa7d33cad1b7b57e5c Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Tue, 17 May 2016 07:53:07 -0500 Subject: [PATCH 3/3] Make list sigil lessons a little more challenging --- lib/koans/03_sigils.ex | 6 +++--- test/koans/sigils_koans_test.exs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/koans/03_sigils.ex b/lib/koans/03_sigils.ex index 9e72ad8..deef195 100644 --- a/lib/koans/03_sigils.ex +++ b/lib/koans/03_sigils.ex @@ -25,15 +25,15 @@ defmodule Sigils do end koan "The ~w sigil creates word lists" do - assert ~w(Hello world) == [___, ___] + assert ~w(Hello world) == ___ end koan "The ~w sigil also allows interpolation" do - assert ~w(Hello 1#{1+1}3) == [___, ___] + assert ~w(Hello 1#{1+1}3) == ___ end koan "The ~W sigil behaves to ~w as ~S behaves to ~s" do - assert ~W(Hello #{1+1}) == ["Hello", ___] + assert ~W(Hello #{1+1}) == ___ end end diff --git a/test/koans/sigils_koans_test.exs b/test/koans/sigils_koans_test.exs index 0821eaa..096fff2 100644 --- a/test/koans/sigils_koans_test.exs +++ b/test/koans/sigils_koans_test.exs @@ -9,9 +9,9 @@ defmodule SigilsTests do true, "1 + 1 = 2", ~S(1 + 1 = #{1+1}), - {:multiple, ["Hello", "world"]}, - {:multiple, ["Hello", "123"]}, - ~S(#{1+1}), + ["Hello", "world"], + ["Hello", "123"], + ["Hello", ~S(#{1+1})], ] test_all(Sigils, answers)