File: headline_spec.rb

package info (click to toggle)
ruby-org 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,476 kB
  • ctags: 213
  • sloc: ruby: 2,748; lisp: 50; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'spec_helper'

describe Orgmode::Headline do

  it "should recognize headlines that start with asterisks" do
    Orgmode::Headline.headline?("*** test\n").should_not be_nil
  end

  it "should reject headlines without headlines at the start" do
    Orgmode::Headline.headline?("  nope!").should be_nil
    Orgmode::Headline.headline?("  tricked you!!!***").should be_nil
  end

  it "should reject improper initialization" do
    lambda { Orgmode::Headline.new " tricked**" }.should raise_error
  end

  it "should properly determine headline level" do
    samples = ["* one", "** two", "*** three", "**** four"]
    expected = 1
    samples.each do |sample|
      h = Orgmode::Headline.new sample
      h.level.should eql(expected)
      expected += 1
    end
  end

  it "should properly determine headline level with offset" do
    h = Orgmode::Headline.new("* one", nil, 1)
    h.level.should eql(2)
  end

  it "should find simple headline text" do
    h = Orgmode::Headline.new "*** sample"
    h.headline_text.should eql("sample")
  end

  it "should understand tags" do
    h = Orgmode::Headline.new "*** sample :tag:tag2:\n"
    h.headline_text.should eql("sample")
    h.should have(2).tags
    h.tags[0].should eql("tag")
    h.tags[1].should eql("tag2")
  end

  it "should understand a single tag" do
    h = Orgmode::Headline.new "*** sample :tag:\n"
    h.headline_text.should eql("sample")
    h.should have(1).tags
    h.tags[0].should eql("tag")
  end

  it "should understand keywords" do
    h = Orgmode::Headline.new "*** TODO Feed cat  :home:"
    h.headline_text.should eql("Feed cat")
    h.keyword.should eql("TODO")
  end

  it "should recognize headlines marked as COMMENT" do
    h = Orgmode::Headline.new "* COMMENT This headline is a comment"
    h.comment_headline?.should_not be_nil
  end
end