You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rsvp-reader/spec/Chapter.spec.js

53 lines
1.4 KiB
JavaScript

5 years ago
import { Chapter, _privates } from '../src/Chapter.js'
const { getNextBiggerNumber } = _privates
describe('Chapter', function() {
const demoText =
'Hello World. Foo bar baz. Lorem ipsum dolor sit. Worttrennungsalgorithmus.'
it('Iterates through segments', function() {
let chapter = new Chapter(demoText, 7)
let i = 1
while (chapter.next()) i++
expect(i).toBe(13)
})
it('Iterates through words', function() {
let chapter = new Chapter(demoText, 7)
let i = 1
while (chapter.nextWord()) i++
expect(i).toBe(10)
})
it('Iterates through sentences', function() {
let chapter = new Chapter(demoText)
let i = 1
while (chapter.nextSentence()) i++
expect(i).toBe(4)
})
it('Iterators return null on finish', function() {
let chapter = new Chapter(demoText, 7)
let cur
while ((cur = chapter.next())) {}
expect(cur).toBe(null)
while ((cur = chapter.prev())) {}
expect(cur).toBe(null)
while ((cur = chapter.nextWord())) {}
expect(cur).toBe(null)
while ((cur = chapter.prevWord())) {}
expect(cur).toBe(null)
while ((cur = chapter.nextSentence())) {}
expect(cur).toBe(null)
while ((cur = chapter.prevSentence())) {}
expect(cur).toBe(null)
})
})
describe('nextBiggerNumber', function() {
it('Returns a the next bigger number', function() {
expect(getNextBiggerNumber(5, [1, 4, 6])).toBe(6)
})
})