stringx_spec.lua

local sh = require 'lsh'

describe('stringx', function()
  it('splits on whitespace', function()
    assert.are.same({'one', 'two', 'three'}, sh.stringx.split('one two  three'))
  end)

  it('splits on a separator', function()
    assert.are.same({'one ', 'wo  ', 'hree'}, sh.stringx.split('one two  three', 't'))
  end)

  it('limits the number of splits', function()
    assert.are.same({'a', 'b,c'}, sh.stringx.split('a,b,c', ',', 1))
  end)

  it('quotes shell words', function()
    assert.are.equal('abc/d-e_f.g', sh.stringx.quote('abc/d-e_f.g'))
    assert.are.equal("''", sh.stringx.quote(''))
    assert.are.equal("'dir name'", sh.stringx.quote('dir name'))
    assert.are.equal("'$HOME'", sh.stringx.quote('$HOME'))
    assert.are.equal([['it'\''s']], sh.stringx.quote("it's"))
  end)

  it('removes a final newline', function()
    assert.are.equal('abc', (sh.stringx.chomp('abc\n')))
    assert.are.equal('abc', (sh.stringx.chomp('abc')))
  end)
end)
generated by LDoc 1.5.0 Last updated 2026-10-02 09:04:27 UTC (f69ca05)