# Test cases for JSON to XML conversion in Laszlo frontend
# This tests the patterns described in an article by
# Stefan Goessner which can be found at:
# www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
# see also: http://goessner.net for more info on this approach

module TestJsonXml

# Class DataPatterns
# Each method returns the Ruby equivalent of one of the JSON patterns.
# The JSON and XML conversion patterns are shown below the Ruby value.
# The XML is based on use of the default dataoptions values to the
# valueToElement() function which converts literal objects to
# Laszlo Dataset XML tree representations.
class DataPatterns
    def p1
        return {"e" => nil}
              # "e": null
              # <e/>
    end

    def p2
        return {"e" => "text"}
              # "e": "text"
              # <e>text</e>
    end

    def p3
        return {"e" => {"@name" => "value"}}
              # "e": {"@name": "value"}
              # <e name="value" />
    end

    def p4
        return {"e" => {"@name" => "value", "#text" => "text"}}
              # "e": {"@name": "value", "#text: "text"}
    end

    def p5
        return {"e" => {"a" => "text", "b" => "text"}}
              # "e": {"a": "text", "b: "text"}
              # <e> <a>text</a> <b>text</b> </e>
    end

    def p6
        return {"e" => {"a" => ["text", "text"]}}
              # "e": {"a": ["text", "text"]}
              # <e> <a>text</a> <a>text</a> </e>
    end

    def p7
        return {"e" => {"#text" => "text", "a" => "text"}}
              # "e": {"#text": "text", "a": "text"}
              # <e> text <a>text</a> </e>
    end

end #class
end #module