@@ -417,14 +417,20 @@ defmodule Inspect.MapTest do
417
417
test "basic" do
418
418
assert inspect ( % { 1 => "b" } ) == "%{1 => \" b\" }"
419
419
420
- assert inspect ( % { 1 => "b" , 2 => "c" } , pretty: true , width: 1 ) ==
420
+ assert inspect ( % { 1 => "b" , 2 => "c" } ,
421
+ pretty: true ,
422
+ width: 1 ,
423
+ custom_options: [ sort_maps: true ]
424
+ ) ==
421
425
"%{\n 1 => \" b\" ,\n 2 => \" c\" \n }"
422
426
end
423
427
424
428
test "keyword" do
425
429
assert inspect ( % { a: 1 } ) == "%{a: 1}"
426
- assert inspect ( % { a: 1 , b: 2 } ) == "%{a: 1, b: 2}"
427
- assert inspect ( % { a: 1 , b: 2 , c: 3 } ) == "%{a: 1, b: 2, c: 3}"
430
+ assert inspect ( % { a: 1 , b: 2 } , custom_options: [ sort_maps: true ] ) == "%{a: 1, b: 2}"
431
+
432
+ assert inspect ( % { a: 1 , b: 2 , c: 3 } , custom_options: [ sort_maps: true ] ) ==
433
+ "%{a: 1, b: 2, c: 3}"
428
434
end
429
435
430
436
test "with limit" do
@@ -446,12 +452,12 @@ defmodule Inspect.MapTest do
446
452
test "public modified struct" do
447
453
public = % Public { key: 1 }
448
454
449
- assert inspect ( Map . put ( public , :foo , :bar ) ) ==
455
+ assert inspect ( Map . put ( public , :foo , :bar ) , custom_options: [ sort_maps: true ] ) ==
450
456
"%{__struct__: Inspect.MapTest.Public, foo: :bar, key: 1}"
451
457
end
452
458
453
459
test "private struct" do
454
- assert inspect ( % { __struct__: Private , key: 1 } ) ==
460
+ assert inspect ( % { __struct__: Private , key: 1 } , custom_options: [ sort_maps: true ] ) ==
455
461
"%{__struct__: Inspect.MapTest.Private, key: 1}"
456
462
end
457
463
@@ -486,7 +492,7 @@ defmodule Inspect.MapTest do
486
492
%{__struct__: Inspect.MapTest.Failing, name: "Foo"}
487
493
'''
488
494
489
- assert inspect ( % Failing { name: "Foo" } ) =~ message
495
+ assert inspect ( % Failing { name: "Foo" } , custom_options: [ sort_maps: true ] ) =~ message
490
496
end
491
497
492
498
test "safely inspect bad implementation disables colors" do
@@ -505,7 +511,10 @@ defmodule Inspect.MapTest do
505
511
%{__struct__: Inspect.MapTest.Failing, name: "Foo"}
506
512
'''
507
513
508
- assert inspect ( % Failing { name: "Foo" } , syntax_colors: [ atom: [ :green ] ] ) =~ message
514
+ assert inspect ( % Failing { name: "Foo" } ,
515
+ syntax_colors: [ atom: [ :green ] ] ,
516
+ custom_options: [ sort_maps: true ]
517
+ ) =~ message
509
518
end
510
519
511
520
test "unsafely inspect bad implementation" do
@@ -524,7 +533,7 @@ defmodule Inspect.MapTest do
524
533
'''
525
534
526
535
try do
527
- inspect ( % Failing { name: "Foo" } , safe: false )
536
+ inspect ( % Failing { name: "Foo" } , safe: false , custom_options: [ sort_maps: true ] )
528
537
rescue
529
538
exception in Inspect.Error ->
530
539
assert Exception . message ( exception ) =~ exception_message
@@ -552,14 +561,16 @@ defmodule Inspect.MapTest do
552
561
553
562
while inspecting:
554
563
555
- %{__struct__: Inspect.MapTest.Failing, name: "Foo"}
556
564
'''
557
565
558
566
try do
559
567
Enum . to_list ( % Failing { name: "Foo" } )
560
568
rescue
561
569
exception in Protocol.UndefinedError ->
562
- assert Exception . message ( exception ) =~ exception_message
570
+ message = Exception . message ( exception )
571
+ assert message =~ exception_message
572
+ assert message =~ "__struct__: Inspect.MapTest.Failing"
573
+ assert message =~ "name: \" Foo\" "
563
574
564
575
assert [
565
576
{ Enumerable , :impl_for! , 1 , _ } | _
@@ -617,7 +628,7 @@ defmodule Inspect.MapTest do
617
628
)
618
629
)
619
630
620
- assert inspect ( % Failing { name: "Foo" } ) =~ message
631
+ assert inspect ( % Failing { name: "Foo" } , custom_options: [ sort_maps: true ] ) =~ message
621
632
assert inspected =~ message
622
633
end
623
634
0 commit comments