<commit_before>require 'test/unit'
require 'rubygems'
require 'cfpropertylist'

class TestFormatted < Test::Unit::TestCase
  def test_formatted_with_default
    plist = CFPropertyList::List.new
    plist.value = CFPropertyList::guess({data: 'blah'})
    plist.formatted = true
    assert plist.to_str(CFPropertyList::List::FORMAT_XML) =~ /<plist.*\n\s+<dict>/m
  end
end<commit_msg>added more tests for formatted xml plists<commit_after>require 'test/unit'
require 'rubygems'
require 'cfpropertylist'

class TestFormatted < Test::Unit::TestCase
  def test_formatted_with_libxml
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::LibXMLParser]

    plist = CFPropertyList::List.new
    plist.value = CFPropertyList::guess({data: 'blah'})
    plist.formatted = true
    assert plist.to_str(CFPropertyList::List::FORMAT_XML) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end

  def test_formatted_with_nokogiri
    require File.dirname(__FILE__) + '/../lib/rbNokogiriParser.rb'
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::NokogiriXMLParser]

    plist = CFPropertyList::List.new
    plist.value = CFPropertyList::guess({data: 'blah'})
    plist.formatted = true

    assert plist.to_str(CFPropertyList::List::FORMAT_XML) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end

  def test_formatted_with_rexml
    require File.dirname(__FILE__) + '/../lib/rbREXMLParser.rb'
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::ReXMLParser]

    plist = CFPropertyList::List.new
    plist.value = CFPropertyList::guess({data: 'blah'})
    plist.formatted = true

    assert plist.to_str(CFPropertyList::List::FORMAT_XML) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end



  def test_formatted_with_libxml_and_datastructures
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::LibXMLParser]

    foo = { :foo => "foo", :bar => "bar", :baz => "baz" }
    assert foo.to_plist({:plist_format => CFPropertyList::List::FORMAT_XML, :formatted => true}) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end

  def test_formatted_with_nokogiri_and_datastructures
    require File.dirname(__FILE__) + '/../lib/rbNokogiriParser.rb'
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::NokogiriXMLParser]

    foo = { :foo => "foo", :bar => "bar", :baz => "baz" }
    assert foo.to_plist({:plist_format => CFPropertyList::List::FORMAT_XML, :formatted => true}) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end

  def test_formatted_with_rexml_and_datastructures
    require File.dirname(__FILE__) + '/../lib/rbREXMLParser.rb'
    orig_parsers = CFPropertyList::List.parsers
    CFPropertyList::List.parsers = [CFPropertyList::Binary, CFPropertyList::ReXMLParser]

    foo = { :foo => "foo", :bar => "bar", :baz => "baz" }
    assert foo.to_plist({:plist_format => CFPropertyList::List::FORMAT_XML, :formatted => true}) =~ /<plist.*\n\s+<dict>/m

  ensure
    CFPropertyList::List.parsers = orig_parsers
  end

end
{'fraction_non_alphanumeric': 0.13880855986119145, 'fraction_numerical': 0.0, 'mean_word_length': 4.8232323232323235, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2322480', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1169, 'n_words': 185}