Sha256: 03935f2def313fa2c5f7600a487735311e46dd767edffe4f2b79e9c7ce9cbe23

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

# -*- coding: utf-8 -*-


$: << File.dirname(__FILE__)

require 'helpers'


class TestTextLine < Test::Unit::TestCase

  LINE = '123'

  def line (str = nil)
    str = LINE unless str
    str = str.dup if String === str
    Spacy::TextLine.new str
  end

  def test_new ()
    assert_equal '123', line.to_s
    assert_equal '123', line(123).to_s
    assert_raise(ArgumentError) {line "123\n"}
  end

  def test_insert ()
    assert_equal 'x123', line.insert('x', 0).to_s
    assert_equal '1x23', line.insert('x', 1).to_s
    assert_equal '123x', line.tap{|l| l.insert 'x', l.last}.to_s
    assert_raise(RangeError)    {line.insert 'x', -1}
    assert_raise(RangeError)    {line.tap{|l| l.insert 'x', l.last + 1}}
    assert_raise(ArgumentError) {line.insert "x\n", 0}
  end

  def test_erase ()
    assert_equal '23',  line.erase(0).to_s
    assert_equal '123', line.erase(0, 0).to_s
    assert_equal '23',  line.erase(0, 1).to_s
    assert_equal '13',  line.erase(1, 2).to_s
    assert_equal '',    line.tap{|l| l.erase 0, l.last}.to_s
    assert_equal '1',   line.tap{|l| l.erase 1, l.last}.to_s
    assert_equal '',    line.tap{|l| l.erase l.last, 0}.to_s
    assert_raise(RangeError) {line.erase -1, 0}
    assert_raise(RangeError) {line.tap{|l| l.erase  0, l.last + 1}}
    assert_raise(RangeError) {line.tap{|l| l.erase -1, l.last + 1}}
  end

  def test_ncolumn ()
    assert_equal LINE.size + 1, line.ncolumn
  end

  def test_to_s ()
    assert_equal '123', line.to_s
    assert_equal '', line('').to_s
  end

end# TestTextLine

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spacy-0.1.9 test/test_textline.rb
spacy-0.1.8 test/test_textline.rb
spacy-0.1.4 test/test_textline.rb