Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

don't try to run encoding tests unless 1.9

  • Loading branch information...
commit 64deb6743f7d6d4a3e0dd8a161e16c18656b09bd 1 parent 004ca80
Jonathan Rochkind jrochkind authored

Showing 1 changed file with 44 additions and 32 deletions. Show diff stats Hide diff stats

  1. +44 32 test/encoding_test.rb
76 test/encoding_test.rb
@@ -2,44 +2,56 @@
2 2
3 3
4 4 require 'yaml'
5   -class EncodingTest < Test::Unit::TestCase
  5 +
  6 +unless "".respond_to?(:encoding)
  7 + puts <<eos
6 8
  9 +=================================================================
  10 + WARNING: Can't run encoding tests unless under ruby 1.9 (#{__FILE__}).
  11 + Encoding tests will NOT be run.
  12 +=================================================================
  13 +
  14 +eos
  15 +else
  16 +
  17 + class EncodingTest < Test::Unit::TestCase
7 18
8   - def test_kev
9   - # Load from string explicitly set to binary, to make sure it ends up utf-8
10   - # anyhow.
11   - raw_kev = "url_ver=Z39.88-2004&url_tim=2003-04-11T10%3A09%3A15TZD&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx&ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&ctx_id=10_8&ctx_tim=2003-04-11T10%3A08%3A30TZD&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.aulast=Vergnaud&rft.auinit=J.-R&rft.btitle=D%C3%A9pendances+et+niveaux+de+repr%C3%A9sentation+en+syntaxe&rft.date=1985&rft.pub=Benjamins&rft.place=Amsterdam%2C+Philadelphia&rfe_id=urn%3Aisbn%3A0262531283&rfe_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfe.genre=book&rfe.aulast=Chomsky&rfe.auinit=N&rfe.btitle=Minimalist+Program&rfe.isbn=0262531283&rfe.date=1995&rfe.pub=The+MIT+Press&rfe.place=Cambridge%2C+Mass&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Asch_svc&svc.abstract=yes&rfr_id=info%3Asid%2Febookco.com%3Abookreader".force_encoding("ascii-8bit")
12   -
13   - assert_equal("ASCII-8BIT", raw_kev.encoding.name)
14   -
15   - ctx = OpenURL::ContextObject.new_from_kev(raw_kev)
  19 +
  20 + def test_kev
  21 + # Load from string explicitly set to binary, to make sure it ends up utf-8
  22 + # anyhow.
  23 + raw_kev = "url_ver=Z39.88-2004&url_tim=2003-04-11T10%3A09%3A15TZD&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx&ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&ctx_id=10_8&ctx_tim=2003-04-11T10%3A08%3A30TZD&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.aulast=Vergnaud&rft.auinit=J.-R&rft.btitle=D%C3%A9pendances+et+niveaux+de+repr%C3%A9sentation+en+syntaxe&rft.date=1985&rft.pub=Benjamins&rft.place=Amsterdam%2C+Philadelphia&rfe_id=urn%3Aisbn%3A0262531283&rfe_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfe.genre=book&rfe.aulast=Chomsky&rfe.auinit=N&rfe.btitle=Minimalist+Program&rfe.isbn=0262531283&rfe.date=1995&rfe.pub=The+MIT+Press&rfe.place=Cambridge%2C+Mass&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Asch_svc&svc.abstract=yes&rfr_id=info%3Asid%2Febookco.com%3Abookreader".force_encoding("ascii-8bit")
  24 +
  25 + assert_equal("ASCII-8BIT", raw_kev.encoding.name)
  26 +
  27 + ctx = OpenURL::ContextObject.new_from_kev(raw_kev)
  28 +
  29 + assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
  30 + assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
  31 +
  32 + # serialized as utf-8
  33 + assert_equal("UTF-8", ctx.kev.encoding.name)
  34 + end
16 35
17   - assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
18   - assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
19   -
20   - # serialized as utf-8
21   - assert_equal("UTF-8", ctx.kev.encoding.name)
22   - end
  36 + def test_xml
  37 + assert_equal("ASCII-8BIT", @@xml_with_utf8.encoding.name)
  38 +
  39 + ctx = OpenURL::ContextObject.new_from_xml(@@xml_with_utf8)
  40 +
  41 + assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
  42 + assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
23 43
24   - def test_xml
25   - assert_equal("ASCII-8BIT", @@xml_with_utf8.encoding.name)
  44 + # serialized as utf-8
  45 + assert_equal("UTF-8", ctx.xml.encoding.name)
  46 + end
26 47
27   - ctx = OpenURL::ContextObject.new_from_xml(@@xml_with_utf8)
28 48
29   - assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
30   - assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
31   -
32   - # serialized as utf-8
33   - assert_equal("UTF-8", ctx.xml.encoding.name)
34   - end
35   -
36   -
37   -
38   - @@xml_with_utf8 = <<eos
  49 +
  50 + @@xml_with_utf8 = <<eos
39 51 <ctx:context-objects xmlns:ctx='info:ofi/fmt:xml:xsd:ctx' xsi:schemaLocation='info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ctx:context-object identifier='10_8' timestamp='2003-04-11T10:08:30TZD' version='Z39.88-2004'><ctx:referent><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:book</ctx:format><ctx:metadata><rft:book xmlns:rft='info:ofi/fmt:xml:xsd:book' xsi:schemaLocation='info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book'><rft:genre>book</rft:genre><rft:btitle>Dépendances et niveaux de représentation en syntaxe</rft:btitle><rft:date>1985</rft:date><rft:pub>Benjamins</rft:pub><rft:place>Amsterdam, Philadelphia</rft:place><rft:authors><rft:author><rft:aulast>Vergnaud</rft:aulast><rft:auinit>J.-R</rft:auinit></rft:author></rft:authors></rft:book></ctx:metadata></ctx:metadata-by-val></ctx:referent><ctx:referring-entity><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:book</ctx:format><ctx:metadata><rfe:book xmlns:rfe='info:ofi/fmt:xml:xsd:book' xsi:schemaLocation='info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book'><rfe:genre>book</rfe:genre><rfe:btitle>Minimalist Program</rfe:btitle><rfe:isbn>0262531283</rfe:isbn><rfe:date>1995</rfe:date><rfe:pub>The MIT Press</rfe:pub><rfe:place>Cambridge, Mass</rfe:place><rfe:authors><rfe:author><rfe:aulast>Chomsky</rfe:aulast><rfe:auinit>N</rfe:auinit></rfe:author></rfe:authors></rfe:book></ctx:metadata></ctx:metadata-by-val><ctx:identifier>urn:isbn:0262531283</ctx:identifier></ctx:referring-entity><ctx:referrer><ctx:identifier>info:sid/ebookco.com:bookreader</ctx:identifier></ctx:referrer><ctx:service-type><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:sch_svc</ctx:format><ctx:metadata><svc:abstract xmlns:svc='info:ofi/fmt:xml:xsd:sch_svc'>yes</svc:abstract></ctx:metadata></ctx:metadata-by-val></ctx:service-type></ctx:context-object></ctx:context-objects>
40 52 eos
41   -# Make sure it's got a raw encoding, so we can test it winds up utf-8 anyhow
42   -@@xml_with_utf8.force_encoding("ascii-8bit")
43   -
  53 + # Make sure it's got a raw encoding, so we can test it winds up utf-8 anyhow
  54 + @@xml_with_utf8.force_encoding("ascii-8bit")
  55 +
  56 + end
44 57 end
45   -

0 comments on commit 64deb67

Please sign in to comment.
Something went wrong with that request. Please try again.