diff options
| author | AnastasiaSulyagina | 2016-08-18 22:11:42 +0300 |
|---|---|---|
| committer | AnastasiaSulyagina | 2016-08-19 14:50:14 +0300 |
| commit | e81f4ab7deeb40308f240be5ea00091fc8786d7a (patch) | |
| tree | b5418f9149de71c0f05f90cb2b39ab47f46e27b4 /Library/Homebrew/cask/test/plist | |
| parent | 5c7c9de669025bbe4cad9829be39c5cf3b31ad25 (diff) | |
| download | brew-e81f4ab7deeb40308f240be5ea00091fc8786d7a.tar.bz2 | |
init
Diffstat (limited to 'Library/Homebrew/cask/test/plist')
| -rw-r--r-- | Library/Homebrew/cask/test/plist/parser_test.rb | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/test/plist/parser_test.rb b/Library/Homebrew/cask/test/plist/parser_test.rb new file mode 100644 index 000000000..a73d1f7f5 --- /dev/null +++ b/Library/Homebrew/cask/test/plist/parser_test.rb @@ -0,0 +1,106 @@ +require "test_helper" + +describe Plist do + it "parses some hdiutil output okay" do + hdiutil_output = <<-HDIUTILOUTPUT +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>system-entities</key> + <array> + <dict> + <key>content-hint</key> + <string>Apple_partition_map</string> + <key>dev-entry</key> + <string>/dev/disk3s1</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_map</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_partition_scheme</string> + <key>dev-entry</key> + <string>/dev/disk3</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_scheme</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_HFS</string> + <key>dev-entry</key> + <string>/dev/disk3s2</string> + <key>mount-point</key> + <string>/private/tmp/dmg.BhfS2g</string> + <key>potentially-mountable</key> + <true/> + <key>unmapped-content-hint</key> + <string>Apple_HFS</string> + <key>volume-kind</key> + <string>hfs</string> + </dict> + </array> +</dict> +</plist> + HDIUTILOUTPUT + + parsed = Plist.parse_xml(hdiutil_output) + + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 3 + parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[ + /dev/disk3s1 + /dev/disk3 + /dev/disk3s2 + ] + end + + it "can ignore garbage output before xml starts" do + hdiutil_output = <<-HDIUTILOUTPUT +Hello there! I am in no way XML am I?!?! + + That's a little silly... you were expexting XML here! + +What is a parser to do? + +Hopefully <not> explode! + +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>system-entities</key> + <array> + <dict> + <key>content-hint</key> + <string>Apple_HFS</string> + <key>dev-entry</key> + <string>/dev/disk3s2</string> + <key>mount-point</key> + <string>/private/tmp/dmg.BhfS2g</string> + <key>potentially-mountable</key> + <true/> + <key>unmapped-content-hint</key> + <string>Apple_HFS</string> + <key>volume-kind</key> + <string>hfs</string> + </dict> + </array> +</dict> +</plist> + HDIUTILOUTPUT + + parsed = Plist.parse_xml(hdiutil_output) + + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 1 + end + + it "does not choke on empty input" do + Plist.parse_xml("").must_equal {} + end +end |
