Class: MarkdownExec::TestHashDelegator
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- MarkdownExec::TestHashDelegator
show all
- Defined in:
- lib/hash_delegator.rb
Defined Under Namespace
Classes: TestHashDelegatorAppendDivider, TestHashDelegatorBlockFind, TestHashDelegatorBlocksFromNestedFiles, TestHashDelegatorCollectRequiredCodeLines, TestHashDelegatorCommandOrUserSelectedBlock, TestHashDelegatorCountBlockInFilename, TestHashDelegatorCreateAndWriteFile, TestHashDelegatorDetermineBlockState, TestHashDelegatorDisplayRequiredCode, TestHashDelegatorFetchColor, TestHashDelegatorFormatExecutionStreams, TestHashDelegatorFormatReferencesSendColor, TestHashDelegatorHandleBackLink, TestHashDelegatorHandleBlockState, TestHashDelegatorHandleGenericBlock, TestHashDelegatorHandleStream, TestHashDelegatorIterBlocksFromNestedFiles, TestHashDelegatorMenuChromeColoredOption, TestHashDelegatorMenuChromeFormattedOptionWithoutFormat, TestHashDelegatorStartFencedBlock, TestHashDelegatorStringSendColor
Instance Method Summary
collapse
Instance Method Details
2358
2359
2360
2361
|
# File 'lib/hash_delegator.rb', line 2358
def setup
@hd = HashDelegator.new
@mdoc = mock('MarkdownDocument')
end
|
#test_calling_execute_required_lines_calls_command_execute_with_argument_args_value ⇒ Object
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
|
# File 'lib/hash_delegator.rb', line 2363
def test_calling_execute_required_lines_calls_command_execute_with_argument_args_value
pigeon = 'E'
obj = {
output_execution_label_format: '',
output_execution_label_name_color: 'plain',
output_execution_label_value_color: 'plain'
}
c = MarkdownExec::HashDelegator.new(obj)
c.pass_args = pigeon
c.expects(:command_execute).with(
'',
args: pigeon
)
c.execute_required_lines
end
|
#test_indent_all_lines_with_empty_indent ⇒ Object
2426
2427
2428
2429
2430
2431
|
# File 'lib/hash_delegator.rb', line 2426
def test_indent_all_lines_with_empty_indent
body = "Line 1\nLine 2"
indent = ''
assert_equal body, HashDelegator.indent_all_lines(body, indent)
end
|
#test_indent_all_lines_with_indent ⇒ Object
2412
2413
2414
2415
2416
2417
|
# File 'lib/hash_delegator.rb', line 2412
def test_indent_all_lines_with_indent
body = "Line 1\nLine 2"
indent = ' ' expected_result = " Line 1\n Line 2"
assert_equal expected_result, HashDelegator.indent_all_lines(body, indent)
end
|
#test_indent_all_lines_without_indent ⇒ Object
2419
2420
2421
2422
2423
2424
|
# File 'lib/hash_delegator.rb', line 2419
def test_indent_all_lines_without_indent
body = "Line 1\nLine 2"
indent = nil
assert_equal body, HashDelegator.indent_all_lines(body, indent)
end
|
#test_push_link_history_and_trigger_load_with_empty_body ⇒ Object
2385
2386
2387
2388
|
# File 'lib/hash_delegator.rb', line 2385
def test_push_link_history_and_trigger_load_with_empty_body
assert_equal LoadFile::Reuse,
@hd.push_link_history_and_trigger_load.load_file
end
|
#test_push_link_history_and_trigger_load_with_file_key ⇒ Object
Test case for non-empty body with ‘file’ key
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
|
# File 'lib/hash_delegator.rb', line 2398
def test_push_link_history_and_trigger_load_with_file_key
body = ["file: sample_file\nblock: sample_block\nvars:\n KEY: VALUE"]
expected_result = LoadFileLinkState.new(LoadFile::Load,
LinkState.new(block_name: 'sample_block',
document_filename: 'sample_file',
inherited_dependencies: {},
inherited_lines: ['# ', 'KEY="VALUE"']))
assert_equal expected_result,
@hd.push_link_history_and_trigger_load(
link_block_body: body,
selected: FCB.new(block_name: 'sample_block', filename: 'sample_file')
)
end
|
#test_push_link_history_and_trigger_load_without_file_key ⇒ Object
Test case for non-empty body without ‘file’ key
2391
2392
2393
2394
2395
|
# File 'lib/hash_delegator.rb', line 2391
def test_push_link_history_and_trigger_load_without_file_key
body = ["vars:\n KEY: VALUE"]
assert_equal LoadFile::Reuse,
@hd.push_link_history_and_trigger_load(link_block_body: body).load_file
end
|
#test_safeval_rescue_from_error ⇒ Object
2437
2438
2439
2440
|
# File 'lib/hash_delegator.rb', line 2437
def test_safeval_rescue_from_error
HashDelegator.stubs(:error_handler).with('safeval')
assert_nil HashDelegator.safeval('invalid code')
end
|
#test_safeval_successful_evaluation ⇒ Object
2433
2434
2435
|
# File 'lib/hash_delegator.rb', line 2433
def test_safeval_successful_evaluation
assert_equal 4, HashDelegator.safeval('2 + 2')
end
|
#test_set_fcb_title ⇒ Object
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
|
# File 'lib/hash_delegator.rb', line 2442
def test_set_fcb_title
input_output_data = [
{
input: MarkdownExec::FCB.new(title: nil,
body: ["puts 'Hello, world!'"]),
output: "puts 'Hello, world!'"
},
{
input: MarkdownExec::FCB.new(title: '',
body: ['def add(x, y)',
' x + y', 'end']),
output: "def add(x, y)\n x + y\n end\n"
},
{
input: MarkdownExec::FCB.new(title: 'foo', body: %w[bar baz]),
output: 'foo' }
]
input_output_data.each do |data|
input = data[:input]
output = data[:output]
HashDelegator.default_block_title_from_body(input)
assert_equal output, input.title
end
end
|
#test_yield_line_if_selected_with_line ⇒ Object
3080
3081
3082
3083
3084
3085
3086
3087
3088
|
# File 'lib/hash_delegator.rb', line 3080
def test_yield_line_if_selected_with_line
block_called = false
HashDelegator.yield_line_if_selected('Test line', [:line]) do |type, content|
block_called = true
assert_equal :line, type
assert_equal 'Test line', content.body[0]
end
assert block_called
end
|
#test_yield_line_if_selected_without_block ⇒ Object
3098
3099
3100
3101
|
# File 'lib/hash_delegator.rb', line 3098
def test_yield_line_if_selected_without_block
result = HashDelegator.yield_line_if_selected('Test line', [:line])
assert_nil result
end
|
#test_yield_line_if_selected_without_line ⇒ Object
3090
3091
3092
3093
3094
3095
3096
|
# File 'lib/hash_delegator.rb', line 3090
def test_yield_line_if_selected_without_line
block_called = false
HashDelegator.yield_line_if_selected('Test line', [:other]) do |_|
block_called = true
end
refute block_called
end
|