language_test.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package test
  2. import (
  3. "fmt"
  4. "testing"
  5. "path/filepath"
  6. )
  7. const language = "language"
  8. func TestStringWithChars(t *testing.T) {
  9. const expected = `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  10. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  11. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  12. ?(X,Y)
  13. `
  14. var dir_path = getTestDirPath(t, language)
  15. var mod_path = filepath.Join(dir_path, "string", "with_chars.km")
  16. expectStdIO(t, mod_path, "", expected)
  17. }
  18. func TestCps(t *testing.T) {
  19. var dir_path = getTestDirPath(t, language)
  20. var mod_path = filepath.Join(dir_path, "sugar", "cps.km")
  21. var input = func(a string, b string) string {
  22. return fmt.Sprintf("%s\n%s\n", a, b)
  23. }
  24. var output = func(c string) string {
  25. return fmt.Sprintf("Number a:\nNumber b:\n%s\n", c)
  26. }
  27. expectStdIO(t, mod_path, input("1", "2"), output("3"))
  28. expectStdIO(t, mod_path, input("1", "bad"), output("None"))
  29. expectStdIO(t, mod_path, input("bad", "2"), output("None"))
  30. expectStdIO(t, mod_path, input("bad", "bad"), output("None"))
  31. }
  32. func TestPipelineLambda(t *testing.T) {
  33. var dir_path = getTestDirPath(t, language)
  34. var mod_path = filepath.Join(dir_path, "sugar", "pipeline_lambda.km")
  35. expectStdIO(t, mod_path, "", "-1\n1, 3\n")
  36. }
  37. func TestDefaultValue(t *testing.T) {
  38. var dir_path = getTestDirPath(t, language)
  39. var mod_path = filepath.Join(dir_path, "product", "default.km")
  40. expectStdIO(t, mod_path, "", "(0,0)\n")
  41. }
  42. func TestFieldRef(t *testing.T) {
  43. var dir_path = getTestDirPath(t, language)
  44. var mod_path = filepath.Join(dir_path, "product", "proj_ref.km")
  45. expectStdIO(t, mod_path, "", "(1,2)\n1\n(3,2)\n(1,-9)\n1\n[(1,4),(3,2)]\n[(1,2),(5,2)]\n")
  46. }
  47. func TestSwitch(t *testing.T) {
  48. var dir_path = getTestDirPath(t, language)
  49. var mod_path = filepath.Join(dir_path, "sum", "switch.km")
  50. expectStdIO(t, mod_path, "", "Yes\n")
  51. }
  52. func TestBranchRef(t *testing.T) {
  53. var dir_path = getTestDirPath(t, language)
  54. var mod_path = filepath.Join(dir_path, "sum", "case_ref.km")
  55. expectStdIO(t, mod_path, "", "1\n\"2\"\n(ok 77)\n(ok \"88\")\n(failed \"99\")\n(failed \"2\")\n3\n\"9\"\n")
  56. }
  57. func TestMultiSwitch(t *testing.T) {
  58. var dir_path = getTestDirPath(t, language)
  59. var mod_path = filepath.Join(dir_path, "sum", "select.km")
  60. var input = func(x string, y string) string {
  61. return fmt.Sprintf("%s\n%s\n", x, y)
  62. }
  63. var output = func(z string) string {
  64. return fmt.Sprintf("%s\n", z)
  65. }
  66. expectStdIO(t, mod_path, input("A", "A"), output("A"))
  67. expectStdIO(t, mod_path, input("A", "B"), output("C"))
  68. expectStdIO(t, mod_path, input("A", "C"), output("B"))
  69. expectStdIO(t, mod_path, input("B", "A"), output("B"))
  70. expectStdIO(t, mod_path, input("B", "B"), output("B"))
  71. expectStdIO(t, mod_path, input("B", "C"), output("B"))
  72. expectStdIO(t, mod_path, input("C", "A"), output("B"))
  73. expectStdIO(t, mod_path, input("C", "B"), output("A"))
  74. expectStdIO(t, mod_path, input("C", "C"), output("C"))
  75. }