Link Search Menu Expand Document

Text functions

Comparisons

OperationDescriptionSignature
==It returns true if s1 and s2 are equal (case sensitive) and false otherwises1==s2
!=It returns true if s1 and s2 are not equal and false otherwises1!=s2 
eqIgnorecaseLike operation == but case insensitiveeqIgnoreCase(s1,s2)

Example download

scenario "text functions" {
  given "the an input sentence"{
    set input {
      value = "hello world"
    }
  }
  when "do text comparisons" {
    set res1 {
      value = input=="Hello World"
    }
    set res2 {
      value = input=="hello world"
    }
    set res3 {
      value = input!="Hello World"
    }
    set res4 {
      value = input!="hello world"
    }
    set res5 {
      value = eqIgnoreCase(input,"Hello World")
    }
    set res6 {
      value = eqIgnoreCase(input,"hello world")
    }
  }
  then "the results are the expected"{
    assert {
      assertion = !res1 && res2 && res3 && !res4 && res5 && res6
    }
  }
}

Transformations

OperationDescriptionSignature
toUppercaseIt transforms s into uppercasetoUppercase(s)
toLowercaseIt transforms s into lowercasetoLowercase(s)
trimPrefixIt removes the prefix from s if it existstrimPrefix(s,prefix)
trimSuffixIt removes the suffix from s if it existstrimSuffix(s,suffix)
replaceOneIt replaces old by new in s oncereplaceOne(s,old,new)
replaceAllIt replaces old by new in s as many time as ld appearsreplaceAll(s,old,new)

Example download

input {
  arg s {
    default ="Hello world"
  }
}
scenario "check string converter operations" {
  when "convert the input" {
    set res1 {
      value = toLowercase(s)
    }
    set res2 {
      value = toUppercase(s)
    }
    set res3 {
      value = trimPrefix(s,"Hello ")
    }
    set res4 {
      value = trimSuffix(s," world")
    }
    set res5 {
      value = replaceOne(s,"Hello", "Bye")
    }
    set res6 {
      value = replaceAll(s,"o", "a")
    }
  }
  then "check results"{
    assert {
      assertion = (
        res1=="hello world" &&  res2=="HELLO WORLD" &&
        res3 == "world" &&  res4 == "Hello" &&
        res5 == "Bye world" &&  res6 == "Hella warld"
      )
    }
  }
}
OperationDescriptionSignature 
containsIt returns true if s contains text; fails in other case lowercasecontains(s,text) 
hasPrefixIt tests whether the string s begins with prefixhasPrefix(s,prefix) 
hasSuffixIt tests whether the string s ends with suffixhasSuffix(s,suffix) 
countIt counts the number of instances of substr in scount(s,substr) 
indexOfIt returns the index of the first instance of substr in s, or -1 if substr is not present in sindexOf(s,substr) 
lastIndexOfIt returns the index of the last instance of substr in s, or -1 if substr is not present in s.lastIndexOf(s,substr)#

Example download

input {
  arg s {
      default ="Hello world"
  }
}
scenario "check string search operations" {
  when "do the operations" {
      set res1 {
          value = contains(s,"world")
      }
      set res2 {
          value = hasPrefix(s,"Hello")
      }
      set res3 {
          value = hasSuffix(s,"world")
      }
      set res4 {
          value = count(s,"l")
      }
      set res5 {
          value = indexOf(s,"l")
      }
      set res6 {
          value = lastIndexOf(s,"l")
      }
  }
  then "the result is the expected"{
      assert {
          assertion = res1 && res2 && res3 && res4==3 && res5==2 && res6==9
      }
  }
}

Others

OperationDescriptionSignature
splitIt slices s into all substrings separated by sep and returns a slice of the substrings between those separators.split(s,sep)
lenIt returns the number of characters in slen(s)

Example download

input {
  arg s {
      default ="tofu,tempeh,kale,edamame"
  }
}
scenario "test functions with strings" {
  when "do the operations" {
      set elements {
          value = split(s,",")
      }
      print {
          msg = elements[_.index]
          while = _.index < len(elements)
      }
  }
  then "check results"{
      assert {
          assertion = (
              len(elements)==4 && 
              elements[0]=="tofu" && elements[1]=="tempeh" &&
              elements[2]=="kale" && elements[3]=="edamame"   
          )
      }
  }
}
  • To concat strings we just need to do this: "${value},"${value2}"