Created
March 13, 2010 21:30
-
-
Save BanzaiMan/331563 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require File.expand_path('../../../spec_helper', __FILE__) | |
| require 'nkf' | |
| describe "NKF.guess" do | |
| it "guesses encoding of a String in JIS" do | |
| NKF.guess("\e$B$^$D$b$H$f$-$R$m\e(B").should == NKF::JIS | |
| end | |
| it "guesses encoding of a String in EUC" do | |
| NKF.guess("\244\336\244\304\244\342\244\310\244\346\244\255\244\322\244\355").should == NKF::EUC | |
| end | |
| it "guesses encoding of a String in Shift-JIS" do | |
| NKF.guess("\202\334\202\302\202\340\202\306\202\344\202\253\202\320\202\353").should == NKF::SJIS | |
| end | |
| it "guesses encoding of a String in UTF-8" do | |
| NKF.guess("\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8\xE3\x82\x86\xE3\x81\x8D\xE3\x81\xB2\xE3\x82\x8D").should == NKF::UTF8 | |
| end | |
| it "guesses encoding of a String in UTF-16(LE)" do | |
| NKF.guess("\xFF\xFE\x7E\x30\x64\x30\x82\x30\x68\x30\x86\x30\x4d\x30\x72\x30\x8d\x30").should == NKF::UTF16 | |
| end | |
| end | |
| # Skip UTF-32 for now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require File.expand_path('../../../spec_helper', __FILE__) | |
| require 'nkf' | |
| describe "NKF.nkf" do | |
| it "encodes a String to JIS" do | |
| NKF.nkf('--jis','まつもとゆきひろ').should == "\e$B$^$D$b$H$f$-$R$m\e(B" | |
| end | |
| it "encodes a String to EUC" do | |
| NKF.nkf('--euc','まつもとゆきひろ').should == "\244\336\244\304\244\342\244\310\244\346\244\255\244\322\244\355" | |
| end | |
| it "encodes a String to Shift-JIS" do | |
| NKF.nkf('--sjis','まつもとゆきひろ').should == "\202\334\202\302\202\340\202\306\202\344\202\253\202\320\202\353" | |
| end | |
| it "encodes a String to UTF-8 (without BOM)" do | |
| NKF.nkf('--oc=UTF-8','まつもとゆきひろ').should == "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8\xE3\x82\x86\xE3\x81\x8D\xE3\x81\xB2\xE3\x82\x8D" | |
| end | |
| it "encodes a String to UTF-16LE (with BOM)" do | |
| NKF.nkf('--oc=UTF-16LE-BOM','まつもとゆきひろ').should == "\xFF\xFE\x7E\x30\x64\x30\x82\x30\x68\x30\x86\x30\x4d\x30\x72\x30\x8d\x30" | |
| end | |
| it "encodes a String to UTF-16 (without BOM)" do | |
| NKF.nkf('--oc=UTF-16BE','まつもとゆきひろ').should == "\x30\x7E\x30\x64\x30\x82\x30\x68\x30\x86\x30\x4D\x30\x72\x30\x8D" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment