glib2 0.90.7-x86-mingw32 → 0.90.8-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/ChangeLog +68 -0
  2. data/ext/glib2/rbglib.c +51 -15
  3. data/ext/glib2/rbglib.h +10 -2
  4. data/ext/glib2/rbglib_bookmarkfile.c +37 -74
  5. data/ext/glib2/rbglib_completion.c +8 -16
  6. data/ext/glib2/rbglib_convert.c +8 -18
  7. data/ext/glib2/rbglib_error.c +2 -8
  8. data/ext/glib2/rbglib_i18n.c +1 -2
  9. data/ext/glib2/rbglib_iochannel.c +81 -127
  10. data/ext/glib2/rbglib_keyfile.c +38 -86
  11. data/ext/glib2/rbglib_maincontext.c +29 -64
  12. data/ext/glib2/rbglib_mainloop.c +4 -8
  13. data/ext/glib2/rbglib_messages.c +7 -17
  14. data/ext/glib2/rbglib_pollfd.c +7 -14
  15. data/ext/glib2/rbglib_shell.c +3 -6
  16. data/ext/glib2/rbglib_source.c +14 -28
  17. data/ext/glib2/rbglib_spawn.c +7 -14
  18. data/ext/glib2/rbglib_threads.c +2 -4
  19. data/ext/glib2/rbglib_timer.c +7 -14
  20. data/ext/glib2/rbglib_unicode.c +45 -16
  21. data/ext/glib2/rbglib_utils.c +25 -50
  22. data/ext/glib2/rbglib_win32.c +10 -17
  23. data/ext/glib2/rbgobj_boxed.c +9 -21
  24. data/ext/glib2/rbgobj_closure.c +5 -11
  25. data/ext/glib2/rbgobj_enums.c +1 -2
  26. data/ext/glib2/rbgobj_object.c +23 -59
  27. data/ext/glib2/rbgobj_param.c +7 -15
  28. data/ext/glib2/rbgobj_signal.c +25 -65
  29. data/ext/glib2/rbgobj_type.c +36 -81
  30. data/ext/glib2/rbgobj_typeinstance.c +3 -6
  31. data/ext/glib2/rbgobj_typeinterface.c +3 -6
  32. data/ext/glib2/rbgobj_typemodule.c +4 -8
  33. data/ext/glib2/rbgobj_typeplugin.c +2 -4
  34. data/ext/glib2/rbgobj_valuetypes.c +7 -15
  35. data/ext/glib2/rbgobject.c +8 -18
  36. data/ext/glib2/rbgobject.h +3 -0
  37. data/ext/glib2/rbgprivate.h +0 -1
  38. data/ext/glib2/rbgutil.c +3 -6
  39. data/lib/1.8/glib2.so +0 -0
  40. data/lib/1.9/glib2.so +0 -0
  41. data/lib/gnome2-raketask.rb +1 -0
  42. data/lib/mkmf-gnome2.rb +12 -9
  43. data/test-unit/History.txt +43 -1
  44. data/test-unit/Manifest.txt +1 -1
  45. data/test-unit/html/index.html +62 -24
  46. data/test-unit/html/index.html.ja +54 -25
  47. data/test-unit/html/test-unit.css +3 -3
  48. data/test-unit/lib/test/unit/assertions.rb +489 -36
  49. data/test-unit/lib/test/unit/autorunner.rb +40 -0
  50. data/test-unit/lib/test/unit/collector.rb +6 -4
  51. data/test-unit/lib/test/unit/collector/load.rb +48 -5
  52. data/test-unit/lib/test/unit/collector/xml.rb +250 -0
  53. data/test-unit/lib/test/unit/error.rb +4 -3
  54. data/test-unit/lib/test/unit/fixture.rb +12 -3
  55. data/test-unit/lib/test/unit/runner/xml.rb +15 -0
  56. data/test-unit/lib/test/unit/testcase.rb +48 -16
  57. data/test-unit/lib/test/unit/testresult.rb +6 -2
  58. data/test-unit/lib/test/unit/testsuite.rb +24 -2
  59. data/test-unit/lib/test/unit/ui/console/testrunner.rb +65 -28
  60. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +11 -2
  61. data/test-unit/lib/test/unit/ui/xml/testrunner.rb +224 -0
  62. data/test-unit/lib/test/unit/version.rb +1 -1
  63. data/test-unit/test/run-test.rb +7 -0
  64. data/test-unit/test/{test_assertions.rb → test-assertions.rb} +708 -77
  65. data/test-unit/test/test-fixture.rb +37 -0
  66. data/test-unit/test/test-testcase.rb +24 -7
  67. data/test-unit/test/test_testsuite.rb +19 -11
  68. data/test/test_iochannel.rb +9 -9
  69. data/test/test_unicode.rb +44 -31
  70. metadata +8 -5
@@ -300,14 +300,14 @@ pre.code
300
300
  padding: 5px 10px;
301
301
  }
302
302
 
303
- img.eye-catch
303
+ div.eye-catch
304
304
  {
305
305
  float: right;
306
306
  }
307
307
 
308
- dl.feature-list
308
+ div.eye-catch img
309
309
  {
310
- clear: both;
310
+ display: block;
311
311
  }
312
312
 
313
313
  dl.feature-list dd
@@ -45,7 +45,7 @@ module Test
45
45
  # end
46
46
 
47
47
  public
48
- def assert_block(message="assert_block failed.") # :yields:
48
+ def assert_block(message="assert_block failed.") # :yields:
49
49
  _wrap_assertion do
50
50
  if (! yield)
51
51
  raise AssertionFailedError.new(message.to_s)
@@ -62,8 +62,19 @@ module Test
62
62
  public
63
63
  def assert(boolean, message=nil)
64
64
  _wrap_assertion do
65
- assert_block("assert should not be called with a block.") { !block_given? }
66
- assert_block(build_message(message, "<?> is not true.", boolean)) { boolean }
65
+ case message
66
+ when nil, String, Proc
67
+ else
68
+ error_message = "assertion message must be String or Proc: "
69
+ error_message << "<#{message.inspect}>(<#{message.class}>)"
70
+ raise ArgumentError, error_message, filter_backtrace(caller)
71
+ end
72
+ assert_block("assert should not be called with a block.") do
73
+ !block_given?
74
+ end
75
+ assert_block(build_message(message, "<?> is not true.", boolean)) do
76
+ boolean
77
+ end
67
78
  end
68
79
  end
69
80
 
@@ -297,6 +308,31 @@ EOT
297
308
  end
298
309
  end
299
310
 
311
+ ##
312
+ # Passes if +object+ does not .respond_to? +method+.
313
+ #
314
+ # Example:
315
+ # assert_not_respond_to('bugbear', :nonexistence) # -> pass
316
+ # assert_not_respond_to('bugbear', :size) # -> fail
317
+
318
+ public
319
+ def assert_not_respond_to(object, method, message="")
320
+ _wrap_assertion do
321
+ full_message = build_message(message,
322
+ "<?>.kind_of\\?(Symbol) or\n" +
323
+ "<?>.respond_to\\?(:to_str) expected",
324
+ method, method)
325
+ assert_block(full_message) do
326
+ method.kind_of?(Symbol) or method.respond_to?(:to_str)
327
+ end
328
+ full_message = build_message(message,
329
+ "!<?>.respond_to\\?(?) expected\n" +
330
+ "(Class: <?>)",
331
+ object, method, object.class)
332
+ assert_block(full_message) {!object.respond_to?(method)}
333
+ end
334
+ end
335
+
300
336
  ##
301
337
  # Passes if +string+ =~ +pattern+.
302
338
  #
@@ -444,25 +480,49 @@ EOT
444
480
  end
445
481
 
446
482
  ##
447
- # Passes if +regexp+ !~ +string+
483
+ # Passes if +regexp+ !~ +string+
448
484
  #
449
485
  # Example:
450
- # assert_no_match(/two/, 'one 2 three')
486
+ # assert_not_match(/two/, 'one 2 three') # -> pass
487
+ # assert_not_match(/three/, 'one 2 three') # -> fail
451
488
 
452
489
  public
453
- def assert_no_match(regexp, string, message="")
490
+ def assert_not_match(regexp, string, message="")
454
491
  _wrap_assertion do
455
- assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
456
- full_message = build_message(message, "<?> expected to not match\n<?>.", regexp, string)
492
+ assert_instance_of(Regexp, regexp,
493
+ "<REGEXP> in assert_not_match(<REGEXP>, ...) " +
494
+ "should be a Regexp.")
495
+ full_message = build_message(message,
496
+ "<?> expected to not match\n<?>.",
497
+ regexp, string)
457
498
  assert_block(full_message) { regexp !~ string }
458
499
  end
459
500
  end
460
501
 
502
+ ##
503
+ # Deprecated. Use #assert_not_match instead.
504
+ #
505
+ # Passes if +regexp+ !~ +string+
506
+ #
507
+ # Example:
508
+ # assert_no_match(/two/, 'one 2 three') # -> pass
509
+ # assert_no_match(/three/, 'one 2 three') # -> fail
510
+
511
+ public
512
+ def assert_no_match(regexp, string, message="")
513
+ _wrap_assertion do
514
+ assert_instance_of(Regexp, regexp,
515
+ "The first argument to assert_no_match " +
516
+ "should be a Regexp.")
517
+ assert_not_match(regexp, string, message)
518
+ end
519
+ end
520
+
461
521
  UncaughtThrow = {
462
- NameError => /^uncaught throw \`(.+)\'$/,
522
+ NameError => /^uncaught throw \`(.+)\'$/, #`
463
523
  ArgumentError => /^uncaught throw (.+)$/,
464
- ThreadError => /^uncaught throw \`(.+)\' in thread /
465
- } #`
524
+ ThreadError => /^uncaught throw \`(.+)\' in thread / #`
525
+ }
466
526
 
467
527
  ##
468
528
  # Passes if the block throws +expected_object+
@@ -550,7 +610,7 @@ EOT
550
610
  # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
551
611
 
552
612
  public
553
- def assert_in_delta(expected_float, actual_float, delta, message="")
613
+ def assert_in_delta(expected_float, actual_float, delta=0.001, message="")
554
614
  _wrap_assertion do
555
615
  _assert_in_delta_validate_arguments(expected_float,
556
616
  actual_float,
@@ -565,6 +625,31 @@ EOT
565
625
  end
566
626
  end
567
627
 
628
+ ##
629
+ # Passes if +expected_float+ and +actual_float+ are
630
+ # not equal within +delta+ tolerance.
631
+ #
632
+ # Example:
633
+ # assert_not_in_delta(0.05, (50000.0 / 10**6), 0.00002) # -> pass
634
+ # assert_not_in_delta(0.05, (50000.0 / 10**6), 0.00001) # -> fail
635
+
636
+ public
637
+ def assert_not_in_delta(expected_float, actual_float, delta=0.001, message="")
638
+ _wrap_assertion do
639
+ _assert_in_delta_validate_arguments(expected_float,
640
+ actual_float,
641
+ delta)
642
+ full_message = _assert_in_delta_message(expected_float,
643
+ actual_float,
644
+ delta,
645
+ message,
646
+ :negative_assertion => true)
647
+ assert_block(full_message) do
648
+ (expected_float.to_f - actual_float.to_f).abs > delta.to_f
649
+ end
650
+ end
651
+ end
652
+
568
653
  # :stopdoc:
569
654
  private
570
655
  def _assert_in_delta_validate_arguments(expected_float,
@@ -584,26 +669,40 @@ EOT
584
669
  end
585
670
 
586
671
  def _assert_in_delta_message(expected_float, actual_float, delta,
587
- message)
588
- format = <<-EOT
589
- <?> expected but was
590
- <?> (tolerance <?>).
672
+ message, options={})
673
+ if options[:negative_assertion]
674
+ format = <<-EOT
675
+ <?> -/+ <?> expected to not include
676
+ <?>.
677
+ EOT
678
+ else
679
+ format = <<-EOT
680
+ <?> -/+ <?> expected to include
681
+ <?>.
591
682
  EOT
592
- arguments = [expected_float, actual_float, delta]
683
+ end
684
+ arguments = [expected_float, delta, actual_float]
593
685
  normalized_expected = expected_float.to_f
594
686
  normalized_actual = actual_float.to_f
595
687
  normalized_delta = delta.to_f
596
688
  relation_format = nil
597
689
  relation_arguments = nil
598
690
  if normalized_actual < normalized_expected - normalized_delta
599
- relation_format = "<<?> < <?>-<?>(?) <= <?>+<?>(?)>"
691
+ relation_format = "<<?> < <?>-<?>[?] <= <?>+<?>[?]>"
600
692
  relation_arguments = [actual_float,
601
693
  expected_float, delta,
602
694
  normalized_expected - normalized_delta,
603
695
  expected_float, delta,
604
696
  normalized_expected + normalized_delta]
605
- elsif normalized_expected - normalized_delta < normalized_actual
606
- relation_format = "<<?>-<?>(?) <= <?>+<?>(?) < <?>>"
697
+ elsif normalized_actual <= normalized_expected + normalized_delta
698
+ relation_format = "<<?>-<?>[?] <= <?> <= <?>+<?>[?]>"
699
+ relation_arguments = [expected_float, delta,
700
+ normalized_expected - normalized_delta,
701
+ actual_float,
702
+ expected_float, delta,
703
+ normalized_expected + normalized_delta]
704
+ else
705
+ relation_format = "<<?>-<?>[?] <= <?>+<?>[?] < <?>>"
607
706
  relation_arguments = [expected_float, delta,
608
707
  normalized_expected - normalized_delta,
609
708
  expected_float, delta,
@@ -622,6 +721,142 @@ EOT
622
721
 
623
722
  build_message(message, format, *arguments)
624
723
  end
724
+
725
+ public
726
+ # :startdoc:
727
+
728
+ ##
729
+ # Passes if +expected_float+ and +actual_float+ are equal
730
+ # within +epsilon+ relative error of +expected_float+.
731
+ #
732
+ # Example:
733
+ # assert_in_epsilon(10000.0, 9900.0, 0.1) # -> pass
734
+ # assert_in_epsilon(10000.0, 9899.0, 0.1) # -> fail
735
+
736
+ public
737
+ def assert_in_epsilon(expected_float, actual_float, epsilon=0.001,
738
+ message="")
739
+ _wrap_assertion do
740
+ _assert_in_epsilon_validate_arguments(expected_float,
741
+ actual_float,
742
+ epsilon)
743
+ full_message = _assert_in_epsilon_message(expected_float,
744
+ actual_float,
745
+ epsilon,
746
+ message)
747
+ assert_block(full_message) do
748
+ normalized_expected_float = expected_float.to_f
749
+ delta = normalized_expected_float * epsilon.to_f
750
+ (normalized_expected_float - actual_float.to_f).abs <= delta
751
+ end
752
+ end
753
+ end
754
+
755
+ ##
756
+ # Passes if +expected_float+ and +actual_float+ are
757
+ # not equal within +epsilon+ relative error of
758
+ # +expected_float+.
759
+ #
760
+ # Example:
761
+ # assert_not_in_epsilon(10000.0, 9900.0, 0.1) # -> fail
762
+ # assert_not_in_epsilon(10000.0, 9899.0, 0.1) # -> pass
763
+
764
+ public
765
+ def assert_not_in_epsilon(expected_float, actual_float, epsilon=0.001,
766
+ message="")
767
+ _wrap_assertion do
768
+ _assert_in_epsilon_validate_arguments(expected_float,
769
+ actual_float,
770
+ epsilon)
771
+ full_message = _assert_in_epsilon_message(expected_float,
772
+ actual_float,
773
+ epsilon,
774
+ message,
775
+ :negative_assertion => true)
776
+ assert_block(full_message) do
777
+ normalized_expected_float = expected_float.to_f
778
+ delta = normalized_expected_float * epsilon.to_f
779
+ (normalized_expected_float - actual_float.to_f).abs > delta
780
+ end
781
+ end
782
+ end
783
+
784
+ # :stopdoc:
785
+ private
786
+ def _assert_in_epsilon_validate_arguments(expected_float,
787
+ actual_float,
788
+ epsilon)
789
+ {
790
+ expected_float => "first float",
791
+ actual_float => "second float",
792
+ epsilon => "epsilon"
793
+ }.each do |float, name|
794
+ assert_respond_to(float, :to_f,
795
+ "The arguments must respond to to_f; " +
796
+ "the #{name} did not")
797
+ end
798
+ epsilon = epsilon.to_f
799
+ assert_operator(epsilon, :>=, 0.0, "The epsilon should not be negative")
800
+ end
801
+
802
+ def _assert_in_epsilon_message(expected_float, actual_float, epsilon,
803
+ message, options={})
804
+ normalized_expected = expected_float.to_f
805
+ normalized_actual = actual_float.to_f
806
+ normalized_epsilon = epsilon.to_f
807
+ delta = normalized_expected * normalized_epsilon
808
+
809
+ if options[:negative_assertion]
810
+ format = <<-EOT
811
+ <?> -/+ (<?> * <?>)[?] expected to not include
812
+ <?>.
813
+ EOT
814
+ else
815
+ format = <<-EOT
816
+ <?> -/+ (<?> * <?>)[?] expected to include
817
+ <?>.
818
+ EOT
819
+ end
820
+ arguments = [expected_float, expected_float, epsilon, delta,
821
+ actual_float]
822
+
823
+ relation_format = nil
824
+ relation_arguments = nil
825
+ if normalized_actual < normalized_expected - delta
826
+ relation_format = "<<?> < <?>-(<?>*<?>)[?] <= <?>+(<?>*<?>)[?]>"
827
+ relation_arguments = [actual_float,
828
+ expected_float, expected_float, epsilon,
829
+ normalized_expected - delta,
830
+ expected_float, expected_float, epsilon,
831
+ normalized_expected + delta]
832
+ elsif normalized_actual <= normalized_expected + delta
833
+ relation_format = "<<?>-(<?>*<?>)[?] <= <?> <= <?>+(<?>*<?>)[?]>"
834
+ relation_arguments = [expected_float, expected_float, epsilon,
835
+ normalized_expected - delta,
836
+ actual_float,
837
+ expected_float, expected_float, epsilon,
838
+ normalized_expected + delta]
839
+ else
840
+ relation_format = "<<?>-(<?>*<?>)[?] <= <?>+(<?>*<?>)[?] < <?>>"
841
+ relation_arguments = [expected_float, expected_float, epsilon,
842
+ normalized_expected - delta,
843
+ expected_float, expected_float, epsilon,
844
+ normalized_expected + delta,
845
+ actual_float]
846
+ end
847
+
848
+ if relation_format
849
+ format << <<-EOT
850
+
851
+ Relation:
852
+ #{relation_format}
853
+ EOT
854
+ arguments.concat(relation_arguments)
855
+ end
856
+
857
+ build_message(message, format, *arguments)
858
+ end
859
+
625
860
  public
626
861
  # :startdoc:
627
862
 
@@ -634,18 +869,76 @@ EOT
634
869
  # * Arguments to the method
635
870
  #
636
871
  # Example:
637
- # assert_send [[1, 2], :include?, 4]
872
+ # assert_send([[1, 2], :member?, 1]) # -> pass
873
+ # assert_send([[1, 2], :member?, 4]) # -> fail
638
874
 
639
875
  public
640
- def assert_send(send_array, message="")
876
+ def assert_send(send_array, message=nil)
641
877
  _wrap_assertion do
642
- assert_instance_of(Array, send_array, "assert_send requires an array of send information")
643
- assert(send_array.size >= 2, "assert_send requires at least a receiver and a message name")
644
- full_message = build_message(message, <<EOT, send_array[0], AssertionMessage.literal(send_array[1].to_s), send_array[2..-1])
878
+ assert_instance_of(Array, send_array,
879
+ "assert_send requires an array " +
880
+ "of send information")
881
+ assert_operator(send_array.size, :>=, 2,
882
+ "assert_send requires at least a receiver " +
883
+ "and a message name")
884
+ format = <<EOT
645
885
  <?> expected to respond to
646
- <?(?)> with a true value.
886
+ <?(*?)> with a true value but was
887
+ <?>.
647
888
  EOT
648
- assert_block(full_message) { send_array[0].__send__(send_array[1], *send_array[2..-1]) }
889
+ receiver, message_name, *arguments = send_array
890
+ result = nil
891
+ full_message =
892
+ build_message(message,
893
+ format,
894
+ receiver,
895
+ AssertionMessage.literal(message_name.to_s),
896
+ arguments,
897
+ AssertionMessage.delayed_literal {result})
898
+ assert_block(full_message) do
899
+ result = receiver.__send__(message_name, *arguments)
900
+ result
901
+ end
902
+ end
903
+ end
904
+
905
+ ##
906
+ # Passes if the method send doesn't return a true value.
907
+ #
908
+ # +send_array+ is composed of:
909
+ # * A receiver
910
+ # * A method
911
+ # * Arguments to the method
912
+ #
913
+ # Example:
914
+ # assert_not_send([[1, 2], :member?, 1]) # -> fail
915
+ # assert_not_send([[1, 2], :member?, 4]) # -> pass
916
+ def assert_not_send(send_array, message=nil)
917
+ _wrap_assertion do
918
+ assert_instance_of(Array, send_array,
919
+ "assert_not_send requires an array " +
920
+ "of send information")
921
+ assert_operator(send_array.size, :>=, 2,
922
+ "assert_not_send requires at least a receiver " +
923
+ "and a message name")
924
+ format = <<EOT
925
+ <?> expected to respond to
926
+ <?(*?)> with not a true value but was
927
+ <?>.
928
+ EOT
929
+ receiver, message_name, *arguments = send_array
930
+ result = nil
931
+ full_message =
932
+ build_message(message,
933
+ format,
934
+ receiver,
935
+ AssertionMessage.literal(message_name.to_s),
936
+ arguments,
937
+ AssertionMessage.delayed_literal {result})
938
+ assert_block(full_message) do
939
+ result = receiver.__send__(message_name, *arguments)
940
+ not result
941
+ end
649
942
  end
650
943
  end
651
944
 
@@ -828,7 +1121,7 @@ EOT
828
1121
  end
829
1122
 
830
1123
  ##
831
- # Passes if +object+.+predicate+
1124
+ # Passes if +object+.+predicate+ is _true_.
832
1125
  #
833
1126
  # Example:
834
1127
  # assert_predicate([], :empty?) # -> pass
@@ -850,7 +1143,7 @@ EOT
850
1143
  end
851
1144
 
852
1145
  ##
853
- # Passes if +object+.+predicate+
1146
+ # Passes if +object+.+predicate+ is not _true_.
854
1147
  #
855
1148
  # Example:
856
1149
  # assert_not_predicate([1], :empty?) # -> pass
@@ -955,6 +1248,96 @@ EOT
955
1248
  end
956
1249
  end
957
1250
 
1251
+ ##
1252
+ # Passes if +collection+ includes +object+.
1253
+ #
1254
+ # Example:
1255
+ # assert_include([1, 10], 1) # -> pass
1256
+ # assert_include(1..10, 5) # -> pass
1257
+ # assert_include([1, 10], 5) # -> fail
1258
+ # assert_include(1..10, 20) # -> fail
1259
+ def assert_include(collection, object, message=nil)
1260
+ _wrap_assertion do
1261
+ assert_respond_to(collection, :include?,
1262
+ "The collection must respond to :include?.")
1263
+ full_message = build_message(message,
1264
+ "<?> expected to include\n<?>.",
1265
+ collection,
1266
+ object)
1267
+ assert_block(full_message) do
1268
+ collection.include?(object)
1269
+ end
1270
+ end
1271
+ end
1272
+
1273
+ ##
1274
+ # Passes if +collection+ doesn't include +object+.
1275
+ #
1276
+ # Example:
1277
+ # assert_not_include([1, 10], 5) # -> pass
1278
+ # assert_not_include(1..10, 20) # -> pass
1279
+ # assert_not_include([1, 10], 1) # -> fail
1280
+ # assert_not_include(1..10, 5) # -> fail
1281
+ def assert_not_include(collection, object, message=nil)
1282
+ _wrap_assertion do
1283
+ assert_respond_to(collection, :include?,
1284
+ "The collection must respond to :include?.")
1285
+ full_message = build_message(message,
1286
+ "<?> expected to not include\n<?>.",
1287
+ collection,
1288
+ object)
1289
+ assert_block(full_message) do
1290
+ not collection.include?(object)
1291
+ end
1292
+ end
1293
+ end
1294
+
1295
+ ##
1296
+ # Passes if +object+ is empty.
1297
+ #
1298
+ # Example:
1299
+ # assert_empty("") # -> pass
1300
+ # assert_empty([]) # -> pass
1301
+ # assert_empty({}) # -> pass
1302
+ # assert_empty(" ") # -> fail
1303
+ # assert_empty([nil]) # -> fail
1304
+ # assert_empty({1 => 2}) # -> fail
1305
+ def assert_empty(object, message=nil)
1306
+ _wrap_assertion do
1307
+ assert_respond_to(object, :empty?,
1308
+ "The object must respond to :empty?.")
1309
+ full_message = build_message(message,
1310
+ "<?> expected to be empty.",
1311
+ object)
1312
+ assert_block(full_message) do
1313
+ object.empty?
1314
+ end
1315
+ end
1316
+ end
1317
+
1318
+ ##
1319
+ # Passes if +object+ is not empty.
1320
+ #
1321
+ # Example:
1322
+ # assert_not_empty(" ") # -> pass
1323
+ # assert_not_empty([nil]) # -> pass
1324
+ # assert_not_empty({1 => 2}) # -> pass
1325
+ # assert_not_empty("") # -> fail
1326
+ # assert_not_empty([]) # -> fail
1327
+ # assert_not_empty({}) # -> fail
1328
+ def assert_not_empty(object, message=nil)
1329
+ _wrap_assertion do
1330
+ assert_respond_to(object, :empty?,
1331
+ "The object must respond to :empty?.")
1332
+ full_message = build_message(message,
1333
+ "<?> expected to not be empty.",
1334
+ object)
1335
+ assert_block(full_message) do
1336
+ not object.empty?
1337
+ end
1338
+ end
1339
+ end
1340
+
958
1341
  ##
959
1342
  # Builds a failure message. +head+ is added before the +template+ and
960
1343
  # +arguments+ replaces the '?'s positionally in the template.
@@ -966,21 +1349,21 @@ EOT
966
1349
  end
967
1350
 
968
1351
  private
969
- def _wrap_assertion
1352
+ def _wrap_assertion(&block)
970
1353
  @_assertion_wrapped ||= false
971
- unless (@_assertion_wrapped)
1354
+ if @_assertion_wrapped
1355
+ block.call
1356
+ else
972
1357
  @_assertion_wrapped = true
973
1358
  begin
974
1359
  add_assertion
975
- return yield
1360
+ block.call
976
1361
  ensure
977
1362
  @_assertion_wrapped = false
978
1363
  end
979
- else
980
- return yield
981
1364
  end
982
1365
  end
983
-
1366
+
984
1367
  ##
985
1368
  # Called whenever an assertion is made. Define this in classes that
986
1369
  # include Test::Unit::Assertions to record assertion counts.
@@ -1067,6 +1450,14 @@ EOT
1067
1450
  end
1068
1451
  end
1069
1452
 
1453
+ def ensure_diffable_string(string)
1454
+ if string.respond_to?(:encoding) and
1455
+ !string.encoding.ascii_compatible?
1456
+ string = string.dup.force_encoding("ASCII-8BIT")
1457
+ end
1458
+ string
1459
+ end
1460
+
1070
1461
  def prepare_for_diff(from, to)
1071
1462
  if !from.is_a?(String) or !to.is_a?(String)
1072
1463
  from = convert(from)
@@ -1074,6 +1465,8 @@ EOT
1074
1465
  end
1075
1466
 
1076
1467
  if diff_target_string?(from) and diff_target_string?(to)
1468
+ from = ensure_diffable_string(from)
1469
+ to = ensure_diffable_string(to)
1077
1470
  [from, to]
1078
1471
  else
1079
1472
  [nil, nil]
@@ -1117,8 +1510,13 @@ EOM
1117
1510
  if use_pp
1118
1511
  begin
1119
1512
  require 'pp' unless defined?(PP)
1513
+ if HashInspector.target?(object)
1514
+ pp_target = HashInspector.new(object)
1515
+ else
1516
+ pp_target = object
1517
+ end
1120
1518
  begin
1121
- return PP.pp(object, '').chomp
1519
+ return PP.pp(pp_target, '').chomp
1122
1520
  rescue NameError
1123
1521
  end
1124
1522
  rescue LoadError
@@ -1130,6 +1528,61 @@ EOM
1130
1528
  end
1131
1529
  end
1132
1530
 
1531
+ class HashInspector
1532
+ class << self
1533
+ def target?(object)
1534
+ object.is_a?(Hash) or object == ENV
1535
+ end
1536
+
1537
+ def normalize(object)
1538
+ if target?(object)
1539
+ new(object)
1540
+ else
1541
+ object
1542
+ end
1543
+ end
1544
+ end
1545
+
1546
+ def initialize(hash)
1547
+ @hash = hash
1548
+ end
1549
+
1550
+ def inspect
1551
+ @hash.inspect
1552
+ end
1553
+
1554
+ def pretty_print(q)
1555
+ q.group(1, '{', '}') do
1556
+ q.seplist(self, nil, :each_pair) do |k, v|
1557
+ q.group do
1558
+ q.pp(k)
1559
+ q.text('=>')
1560
+ q.group(1) do
1561
+ q.breakable('')
1562
+ q.pp(v)
1563
+ end
1564
+ end
1565
+ end
1566
+ end
1567
+ end
1568
+
1569
+ def pretty_print_cycle(q)
1570
+ q.text(@hash.empty? ? '{}' : '{...}')
1571
+ end
1572
+
1573
+ def each_pair
1574
+ keys = @hash.keys
1575
+ begin
1576
+ keys = keys.sort # FIXME: more cleverly
1577
+ rescue ArgumentError
1578
+ end
1579
+ keys.each do |key|
1580
+ yield(self.class.normalize(key),
1581
+ self.class.normalize(@hash[key]))
1582
+ end
1583
+ end
1584
+ end
1585
+
1133
1586
  class Literal
1134
1587
  def initialize(value)
1135
1588
  @value = value