File: argsof.liq

package info (click to toggle)
liquidsoap 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,372 kB
  • sloc: ml: 71,806; javascript: 27,320; ansic: 398; xml: 114; sh: 99; lisp: 96; makefile: 26
file content (48 lines) | stat: -rw-r--r-- 1,322 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Test argsof directive.
def f() =
  # file.extension: (?dir_sep : string, ?leading_dot : bool, string) -> string

  # Add all labeled arguments
  def g(%argsof(file.extension)) =
    "#{dir_sep}-#{leading_dot}"
  end

  if g() != "/-true" then test.fail() end
  if g(dir_sep="gni") != "gni-true" then test.fail() end
  if g(leading_dot=false) != "/-false" then test.fail() end
  if g(dir_sep="gni", leading_dot=false) != "gni-false" then test.fail() end

  # Add all but leading dot. Add unlabeled argument to test as well
  def g(%argsof(file.extension[!leading_dot]), x) =
    "#{dir_sep}-#{x}"
  end

  if g("bla") != "/-bla" then test.fail() end
  if g(dir_sep="gni", "bla") != "gni-bla" then test.fail() end

  # Add only leading_dot
  def g(%argsof(file.extension[leading_dot]), x) =
    "#{leading_dot}-#{x}"
  end

  if g(leading_dot=false, "bla") != "false-bla" then test.fail() end

  # Test argsof call
  def h(~leading_dot=false, ~dir_sep="no_dir_sep") =
    "#{leading_dot}-#{dir_sep}"
  end

  leading_dot = true
  dir_sep = "/"
  if h(%argsof(file.extension)) != "true-/" then test.fail() end
  if h(%argsof(file.extension[!leading_dot])) != "false-/" then test.fail() end
  if
    h(%argsof(file.extension[leading_dot])) != "true-no_dir_sep"
  then
    test.fail()
  end

  test.pass()
end

test.check(f)