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
2512
2513
2514
2515
|
# File 'lib/hash_delegator.rb', line 2512
def setup
@hd = HashDelegator.new
@mdoc = mock('MarkdownDocument')
end
|
#test_calling_execute_required_lines_calls_command_execute_with_argument_args_value ⇒ Object
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
|
# File 'lib/hash_delegator.rb', line 2517
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
2580
2581
2582
2583
2584
2585
|
# File 'lib/hash_delegator.rb', line 2580
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
2566
2567
2568
2569
2570
2571
|
# File 'lib/hash_delegator.rb', line 2566
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
2573
2574
2575
2576
2577
2578
|
# File 'lib/hash_delegator.rb', line 2573
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
2539
2540
2541
2542
|
# File 'lib/hash_delegator.rb', line 2539
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
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
|
# File 'lib/hash_delegator.rb', line 2552
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
2545
2546
2547
2548
2549
|
# File 'lib/hash_delegator.rb', line 2545
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
2591
2592
2593
2594
|
# File 'lib/hash_delegator.rb', line 2591
def test_safeval_rescue_from_error
HashDelegator.stubs(:error_handler).with('safeval')
assert_nil HashDelegator.safeval('invalid code')
end
|
#test_safeval_successful_evaluation ⇒ Object
2587
2588
2589
|
# File 'lib/hash_delegator.rb', line 2587
def test_safeval_successful_evaluation
assert_equal 4, HashDelegator.safeval('2 + 2')
end
|
#test_set_fcb_title ⇒ Object
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
|
# File 'lib/hash_delegator.rb', line 2596
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
3234
3235
3236
3237
3238
3239
3240
3241
3242
|
# File 'lib/hash_delegator.rb', line 3234
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
3252
3253
3254
3255
|
# File 'lib/hash_delegator.rb', line 3252
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
3244
3245
3246
3247
3248
3249
3250
|
# File 'lib/hash_delegator.rb', line 3244
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
|