File: test_meta.rb

package info (click to toggle)
libwww-mechanize-ruby 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 883
  • sloc: ruby: 6,621; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
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
65
require "helper"

class MetaTest < Test::Unit::TestCase
  Meta = Mechanize::Page::Meta

  #
  # CONTENT_REGEXP test
  #

  def test_content_regexp
    r = Meta::CONTENT_REGEXP

    assert r =~ "0; url=http://localhost:8080/path"
    assert_equal "0", $1
    assert_equal "http://localhost:8080/path", $3

    assert r =~ "100.001; url=http://localhost:8080/path"
    assert_equal "100.001", $1
    assert_equal "http://localhost:8080/path", $3

    assert r =~ "0; url='http://localhost:8080/path'"
    assert_equal "0", $1
    assert_equal "http://localhost:8080/path", $3

    assert r =~ "0; url=\"http://localhost:8080/path\""
    assert_equal "0", $1
    assert_equal "http://localhost:8080/path", $3

    assert r =~ "0; url="
    assert_equal "0", $1
    assert_equal "", $3

    assert r =~ "0"
    assert_equal "0", $1
    assert_equal nil, $3

    assert r =~ "   0;   "
    assert_equal "0", $1
    assert_equal nil, $3

    assert r =~ "0; UrL=http://localhost:8080/path"
    assert_equal "0", $1
    assert_equal "http://localhost:8080/path", $3
  end

  #
  # parse test
  #

  def test_parse_documentation
    uri = URI.parse('http://current.com/')

    assert_equal ['5', 'http://example.com/'], Meta.parse("5;url=http://example.com/", uri)
    assert_equal ['5', 'http://current.com/'], Meta.parse("5;url=", uri)
    assert_equal ['5', 'http://current.com/'], Meta.parse("5", uri)
    assert_equal nil, Meta.parse("invalid content", uri)
  end

  def test_parse_returns_nil_if_no_delay_and_url_can_be_parsed
    uri = URI.parse('http://current.com/')

    assert_equal nil, Meta.parse("invalid content", uri)
    assert_equal nil, Meta.parse("invalid content", uri) {|delay, url| 'not nil' }
  end
end