Sha256: 8c84cfe7e0ec5bb2a238cb092433dcc626d25ec9ebdf4fd33d405f7157479085

Contents?: true

Size: 1017 Bytes

Versions: 3

Compression:

Stored size: 1017 Bytes

Contents

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


$: << File.dirname(__FILE__)

require 'helpers'


class TestText < Test::Unit::TestCase

  LINES = %w[123 456]

  def buffer (str = nil)
    str = LINES.join("\n") unless str
    str = str.dup if String === str
    Spacy::TextBuffer.new str
  end

  def text ()
    Spacy::Text.new buffer
  end

  def test_pos ()
    lineend = LINES[0].size
    assert_equal [0, 0],       text.cursor
    assert_equal [0, 1],       text.tap{|t| t.pos += 1}.cursor
    assert_equal [0, lineend], text.tap{|t| t.pos = lineend}.cursor
    assert_equal [1, 0],       text.tap{|t| t.pos = lineend + 1}.cursor
  end

  def test_cursor ()
    lineend = LINES[0].size
    size    = LINES.inject(0) {|n, s| n + s.size + 1} - 1
    assert_equal lineend, text.tap{|t| t.cursor = 0, lineend}.pos
    assert_equal size,    text.tap{|t| t.cursor = 1, 4}.pos
  end

  def test_row ()
    assert_equal [1, 0], text.tap{|t| t.row += 1}.cursor
    assert_equal [0, 1], text.tap{|t| t.column += 1}.cursor
  end

end# TestText

Version data entries

3 entries across 3 versions & 1 rubygems

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