Sha256: e1bdcac17fd8788bb7c4fefe3cefdf7d2c1187ef06368ef85f3eecdeab12aaf6

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

# coding: utf-8

require 'spec_helper'

RSpec.describe Verse::Alignment, '.left' do
  it "aligns line to left" do
    text = "the madness of men"
    alignment = Verse::Alignment.new(text)
    expect(alignment.left(22)).to eq("the madness of men    ")
  end

  it "fills empty" do
    alignment = Verse::Alignment.new('')
    expect(alignment.left(22)).to eq("                      ")
  end

  it "left justifies utf line" do
    text = "こんにちは"
    alignment = Verse::Alignment.new(text)
    expect(alignment.align(20, :left)).to eq("こんにちは          ")
  end

  it "aligns multiline text to left" do
    text = "for there is no folly of the beast\nof the earth which\nis not infinitely\noutdone by the madness of men"
    alignment = Verse::Alignment.new(text)
    expect(alignment.left(40)).to eq([
     "for there is no folly of the beast      \n",
     "of the earth which                      \n",
     "is not infinitely                       \n",
     "outdone by the madness of men           "
    ].join)
  end

  it "left justifies multiline utf text" do
    text = "ラドクリフ\n、マラソン五輪\n代表に1万m出\n場にも含み"
    alignment = Verse::Alignment.new(text)
    expect(alignment.left(20)).to eq([
      "ラドクリフ          \n",
      "、マラソン五輪      \n",
      "代表に1万m出        \n",
      "場にも含み          "
    ].join)
  end

  it "centers multiline text with fill of '*'" do
    text = "for there is no folly of the beast\nof the earth which\nis not infinitely\noutdone by the madness of men"
    alignment = Verse::Alignment.new(text, fill: '*')
    expect(alignment.left(40)).to eq([
     "for there is no folly of the beast******\n",
     "of the earth which**********************\n",
     "is not infinitely***********************\n",
     "outdone by the madness of men***********"
    ].join)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
verse-0.3.0 spec/unit/alignment/left_spec.rb
verse-0.2.1 spec/unit/alignment/left_spec.rb