Commits

Doug Burke committed 142b16a

Turtle/N3 format: \f in string literals is now converted to \u000C (interoperability issue)

  • Participants
  • Parent commits 9f36ed2
  • Tags 0.9.0.6

Comments (0)

Files changed (4)

 0.9.0.6:
 
+  Turtle/N3 output: \f characters in literals are converted to
+  \u000C to work around some interoperability issues.
+
   Changed the test handling to use test-framework.
 
 0.9.0.5:

File src/Swish/RDF/Graph.hs

 
 -- The Data.Text API points out issues with processing a text
 -- character-by-character, but it's not clear to me how to avoid
--- that here
+-- that here.
 --
 -- One assumption would be that the strings aren't likely to be large,
 -- so that several calls to T.find or similar could be made to
 processChar '\r' = ("\\r", True)
 processChar '\t' = ("\\t", True)
 processChar '\b' = ("\\b", True)
-processChar '\f' = ("\\f", True)
+-- processChar '\f' = ("\\f", True)
+-- Using the above I get invalid output according to
+-- rapper version 2.0.9, so use the following for now
+-- (changed at version 0.9.0.6)
+processChar '\f' = ("\\u000C", True) -- 
 processChar c =
   let nc = ord c
       -- lazy ways to convert to hex-encoded strings
 --   At present the choice is between using one or three
 --   double quote (@"@) characters to surround the string; i.e. using
 --   single quote (@'@)  characters is not supported.
-
+-- 
+--   As of Swish 0.9.0.6, the @\f@ character is converted to
+--   @\u000C@ rather than left as is to aid interoperability
+--   with some other tools.
+--   
 quote :: 
   Bool  -- ^ @True@ if the string is to be displayed using one rather than three quotes.
   -> String -- ^ String to quote.
   .
   Changes in version @0.9.0.6@:
   .
+  * Turtle/N3 output: @\f@ characters in literals are converted to
+  @\u000C@ to work around some interoperability issues.
+  .
   * Changed the test handling to use @test-framework@.
   .
   Changes in version @0.9.0.5@:

File tests/TurtleTest.hs

           Left e -> parseFail e ttl
           Right gr -> expectedGraph @=? gr
          
-        
   in TF.testGroup lbl
      [ TF.testCase "base case" compareTriples
      , TF.testCase "round-trip example" compareRoundTrip
      ]
-     
+
+-- | Check that both graphs (in Turtle format) are
+--   the same, once parsed.
+-- 
 compareGraphs :: String -> T.Text -> T.Text -> TF.Test
 compareGraphs l t1 t2 =
   let ans = case (toGraph t1, toGraph t2) of
         (_, Left e2) -> parseFail e2 t2 -- "graph 2 of " ++ l
         (Right gr1, Right gr2) -> gr1 @=? gr2
   in TF.testCase ("example: " ++ l) ans
-      
+
+-- | Check that the list of triples creates the output
+--   graph. It is intended for very-small graphs.
+--
+checkFormat :: String -> [RDFTriple] -> T.Text -> TF.Test
+checkFormat lbl ts egr =
+  let gr = toRDFGraph $ S.fromList ts
+      ogr = formatGraphAsText gr
+  in TF.testCase ("format: " ++ lbl) $ egr @=? ogr
+
 -- *********************************************
 -- Examples from Turtle specification
 -- *********************************************
 
 -- Cases to try and improve the test coverage
 
+urnA, urnB :: URI
+urnA = toURI "urn:a"
+urnB =  toURI "urn:b"
+
 trips :: T.Text -> [RDFTriple]
-trips t = [triple (toURI "urn:a") (toURI "urn:b") (Lit t)]
+trips t = [triple urnA urnB (Lit t)]
 
 coverageCases :: TF.Test
 coverageCases =
   , compareExample "cov4"
     "<urn:a> <urn:b> \"3\\\\8\\\\11\" ."
     (trips "3\\8\\11")
+  , checkFormat "\\f" (trips "A\ffB")
+    "@prefix : <urn:a> .\n<urn:a> <urn:b> \"A\\u000CfB\" .\n"
   ]
 
 -- Extracted from failures seen when using the W3C test suite