require 'test/unit'
require_relative '../ttm/todo_2_json'
class TestTodo2Json < Test::Unit::TestCase
def setup
@todo_2_json = Todo2Json.new
end
def test_get_todo_json
todo = "準備[アクティビティのコミット,メールチェック]|1|2012/02/06 09:01:28|2012/02/06 09:08:34|0時間7分6秒"
json = @todo_2_json.get_todo_json todo
expected = <<"EOS"
"todo":{
"task":"準備[アクティビティのコミット,メールチェック]",
"estimate":"1",
"actualResultsTime":"0時間7分6秒"
}
EOS
assert_equal(expected.chomp, json)
end
def test_get_todo_json_nil
todo = nil
json = @todo_2_json.get_todo_json todo
expected = ""
assert_equal(expected, json)
end
def test_get_todo_json_empty
todo = ""
json = @todo_2_json.get_todo_json todo
expected = ""
assert_equal(expected, json)
end
def test_get_todo_json_length
todo = "a|b|c|d|e|f"
json = @todo_2_json.get_todo_json(todo)
expected = ""
assert_equal(expected, json)
todo = "a|b|c|d"
json = @todo_2_json.get_todo_json todo
expected = ""
assert_equal(expected, json)
todo = "abcde"
json = @todo_2_json.get_todo_json todo
expected = ""
assert_equal(expected, json)
end
def test_get_daily_json
daily =<<"EOS"
2012/02/08
タスク1|見積1|開始時間1|終了時間1|実績時間1
タスク2|見積2|開始時間2|終了時間2|実績時間2
タスク3|見積3|開始時間3|終了時間3|実績時間3
EOS
json = @todo_2_json.get_daily_json daily
expected =<<"EOS"
{"date":"2012/02/08"},
[
{
"todo":{
"task":"タスク1",
"estimate":"見積1",
"actualResultsTime":"実績時間1"
}
},
{
"todo":{
"task":"タスク2",
"estimate":"見積2",
"actualResultsTime":"実績時間2"
}
},
{
"todo":{
"task":"タスク3",
"estimate":"見積3",
"actualResultsTime":"実績時間3"
}
}
]
EOS
assert_equal(expected, json)
end
def test_get_daily_json_empty
daily = ""
json = @todo_2_json.get_daily_json daily
expected = ""
assert_equal(expected, json)
end
def test_get_daily_json_nil
daily = nil
json = @todo_2_json.get_daily_json daily
expected = ""
assert_equal(expected, json)
end
def test_get_daily_json_1line
daily = "2012/02/08"
json = @todo_2_json.get_daily_json daily
expected = ""
assert_equal(expected, json)
end
def test_get_daily_json_1line
daily =<<"EOS"
2012/02/08
タスク1|見積1|開始時間1|終了時間1|実績時間1|aaa
タスク2|見積2|開始時間2|
タスク3見積3開始時間3終了時間3実績時間3
EOS
json = @todo_2_json.get_daily_json daily
expected = ""
assert_equal(expected, json)
end
def test_get_monthly_json
monthly =<<"EOS"
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|終了時間0208-1|実績時間0208-1
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1
■2012/02/10
タスク0210-1|見積0210-1|開始時間0210-1|終了時間0210-1|実績時間0210-1
EOS
json = @todo_2_json.get_monthly_json monthly
expected =<<"EOS"
[
{"date":"2012/02/08"},
[
{
"todo":{
"task":"タスク0208-1",
"estimate":"見積0208-1",
"actualResultsTime":"実績時間0208-1"
}
}
]
],
[
{"date":"2012/02/09"},
[
{
"todo":{
"task":"タスク0209-1",
"estimate":"見積0209-1",
"actualResultsTime":"実績時間0209-1"
}
}
]
],
[
{"date":"2012/02/10"},
[
{
"todo":{
"task":"タスク0210-1",
"estimate":"見積0210-1",
"actualResultsTime":"実績時間0210-1"
}
}
]
]
EOS
assert_equal(expected.chomp, json)
end
def test_get_monthly_json_empty
monthly = ""
json = @todo_2_json.get_monthly_json monthly
assert false
rescue => exc
expected = Todo2Json::ERR_MONTHLY
assert_equal(expected, exc.message)
end
def test_get_monthly_json_nil
monthly = nil
json = @todo_2_json.get_monthly_json monthly
assert false
rescue => exc
expected = Todo2Json::ERR_MONTHLY
assert_equal(expected, exc.message)
end
def test_get_monthly_json_nodata
monthly = "あああ\nあああ"
json = @todo_2_json.get_monthly_json monthly
assert false
rescue => exc
expected = Todo2Json::ERR_MONTHLY
assert_equal(expected, exc.message)
end
def test_get_monthly_json_no_valid_data
monthly = <<"EOS"
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|情報不足
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1|情報過多
EOS
json = @todo_2_json.get_monthly_json monthly
assert false
rescue => exc
expected = Todo2Json::ERR_MONTHLY
assert_equal(expected, exc.message)
end
end