File: test_task_arguments.rb

package info (click to toggle)
rake 0.8.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,084 kB
  • ctags: 1,133
  • sloc: ruby: 8,223; makefile: 46; ansic: 20
file content (76 lines) | stat: -rw-r--r-- 2,028 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
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env ruby

require 'test/unit'
require 'rake'

######################################################################
class TestTaskArguments < Test::Unit::TestCase
  def teardown
    ENV.delete('rev')
    ENV.delete('VER')
  end

  def test_empty_arg_list_is_empty
    ta = Rake::TaskArguments.new([], [])
    assert_equal({}, ta.to_hash)
  end

  def test_multiple_values_in_args
    ta = Rake::TaskArguments.new([:a, :b, :c], [:one, :two, :three])
    assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash)
  end

  def test_to_s
    ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
    assert_equal ta.to_hash.inspect, ta.to_s
    assert_equal ta.to_hash.inspect, ta.inspect
  end

  def test_enumerable_behavior
    ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2 ,3])
    assert_equal [10, 20, 30], ta.collect { |k,v| v * 10 }.sort
  end

  def test_named_args
    ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
    assert_equal 1, ta.aa
    assert_equal 1, ta[:aa]
    assert_equal 1, ta["aa"]
    assert_equal 2, ta.bb
    assert_nil ta.cc
  end

  def test_args_knows_its_names
    ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
    assert_equal ["aa", "bb"], ta.names
  end

  def test_extra_names_are_nil
    ta = Rake::TaskArguments.new(["aa", "bb", "cc"], [1, 2])
    assert_nil ta.cc
  end

  def test_args_can_reference_env_values
    ta = Rake::TaskArguments.new(["aa"], [1])
    ENV['rev'] = "1.2"
    ENV['VER'] = "2.3"
    assert_equal "1.2", ta.rev
    assert_equal "2.3", ta.ver
  end

  def test_creating_new_argument_scopes
    parent = Rake::TaskArguments.new(['p'], [1])
    child = parent.new_scope(['c', 'p'])
    assert_equal({:c => nil, :p=>1}, child.to_hash)
    assert_equal 1, child.p
    assert_equal 1, child["p"]
    assert_equal 1, child[:p]
    assert_nil child.c
  end

  def test_child_hides_parent_arg_names
    parent = Rake::TaskArguments.new(['aa'], [1])
    child = Rake::TaskArguments.new(['aa'], [2], parent)
    assert_equal 2, child.aa
  end
end