General refactor.

This commit is contained in:
2018-03-07 18:56:12 +00:00
parent e9f4aae440
commit 967687dfd1
33 changed files with 637 additions and 587 deletions

View File

@@ -32,45 +32,46 @@ namespace Claunia.Encoding.Tests
public class ATASCII
{
const string Punctuations = "!\"#$%&'()*+,-./:;<=>?@[\\]^_|";
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7C };
readonly byte[] PunctuationsBytes =
{
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C,
0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7C
};
const string Digits = "0123456789";
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
readonly byte[] UpperLatinBytes =
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
};
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
readonly byte[] LowerLatinBytes =
{
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
};
const string Graphics = "├┘┤┐╱╲◢▗◣▝▘▂▖┌─┼●▄▎┬┴▌└";
readonly byte[] GraphicsBytes = { 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A};
readonly byte[] GraphicsBytes =
{
0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1A
};
const string Arrows = "↑↓←→↰◀▶";
readonly byte[] ArrowsBytes = {0x1C, 0x1D, 0x1E, 0x1F, 0x7D, 0x7E, 0x7F};
const string Decks = "♥♣♦♠";
readonly byte[] DecksBytes = {0x00, 0x10, 0x60, 0x7B};
[Test]
public void UnicodeToAtari()
public void AtariPangrams()
{
byte[] byteArray;
string testString;
byteArray = Encoding.AtariEncoding.GetBytes(Punctuations);
Assert.AreEqual(PunctuationsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Digits);
Assert.AreEqual(DigitsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(UpperLatin);
Assert.AreEqual(UpperLatinBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(LowerLatin);
Assert.AreEqual(LowerLatinBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Graphics);
Assert.AreEqual(GraphicsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Arrows);
Assert.AreEqual(ArrowsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Decks);
Assert.AreEqual(DecksBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Pangrams.English);
testString = Encoding.AtariEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.English, testString);
}
[Test]
@@ -96,14 +97,25 @@ namespace Claunia.Encoding.Tests
}
[Test]
public void AtariPangrams()
public void UnicodeToAtari()
{
byte[] byteArray;
string testString;
byteArray = Encoding.AtariEncoding.GetBytes(Pangrams.English);
testString = Encoding.AtariEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.English, testString);
byteArray = Encoding.AtariEncoding.GetBytes(Punctuations);
Assert.AreEqual(PunctuationsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Digits);
Assert.AreEqual(DigitsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(UpperLatin);
Assert.AreEqual(UpperLatinBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(LowerLatin);
Assert.AreEqual(LowerLatinBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Graphics);
Assert.AreEqual(GraphicsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Arrows);
Assert.AreEqual(ArrowsBytes, byteArray);
byteArray = Encoding.AtariEncoding.GetBytes(Decks);
Assert.AreEqual(DecksBytes, byteArray);
}
}
}

View File

@@ -25,7 +25,6 @@
// THE SOFTWARE.
using NUnit.Framework;
using System.Runtime.InteropServices;
namespace Claunia.Encoding.Tests
{
@@ -33,44 +32,153 @@ namespace Claunia.Encoding.Tests
public class AtariST
{
const string Punctuations = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x7B, 0x7C, 0x7D, 0x7E };
readonly byte[] PunctuationsBytes =
{
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C,
0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x7B, 0x7C, 0x7D, 0x7E
};
const string Digits = "0123456789";
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
readonly byte[] UpperLatinBytes =
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
};
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
readonly byte[] LowerLatinBytes =
{
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
};
const string Spanish = "¡¿áéíóúüñÉÜÑ";
readonly byte[] SpanishBytes = {0xAD, 0xA8, 0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x81, 0xA4, 0x90, 0x9A, 0xA5};
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
readonly byte[] FrenchBytes = { 0x82, 0x90, 0x85, 0x8A, 0x97, 0xB6, 0x83, 0x88, 0x8C, 0x93, 0x96, 0x89, 0x8B, 0x81, 0x98, 0x87, 0x80, 0xB4, 0xB5, 0x91, 0x92 };
readonly byte[] FrenchBytes =
{
0x82, 0x90, 0x85, 0x8A, 0x97, 0xB6, 0x83, 0x88, 0x8C, 0x93, 0x96, 0x89, 0x8B, 0x81, 0x98, 0x87, 0x80, 0xB4,
0xB5, 0x91, 0x92
};
const string German = "äöüßÄÖÜ";
readonly byte[] GermanBytes = {0x84, 0x94, 0x81, 0x9E, 0x8E, 0x99, 0x9A};
const string Norwegian = "æøåÆØÅ";
readonly byte[] NorwegianBytes = {0x91, 0xB3, 0x86, 0x92, 0xB2, 0x8F};
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
readonly byte[] PortugueseBytes = { 0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x90, 0x83, 0x88, 0x93, 0xB0, 0xB1, 0xB7, 0xB8, 0x87, 0x80 };
readonly byte[] PortugueseBytes =
{0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x90, 0x83, 0x88, 0x93, 0xB0, 0xB1, 0xB7, 0xB8, 0x87, 0x80};
const string Dutch = "ijIJ";
readonly byte[] DutchBytes = {0xC0, 0xC1};
const string Hebrew = "אבגדהוזחטיכלמנסעפצקרשתןךםףץ";
readonly byte[] HebrewBytes = { 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC};
readonly byte[] HebrewBytes =
{
0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3,
0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC
};
const string Greek = "αβΓπΣσµτΦΘΩδ¯";
readonly byte[] GreekBytes = {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xFF};
const string Typographic = "ªº«»¨´†¶©®™§°∙·";
readonly byte[] TypographicBytes = { 0xA6, 0xA7, 0xAE, 0xAF, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xDD, 0xF8, 0xF9, 0xFA };
readonly byte[] TypographicBytes =
{0xA6, 0xA7, 0xAE, 0xAF, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xDD, 0xF8, 0xF9, 0xFA};
const string Currency = "¢£¥ƒ";
readonly byte[] CurrencyBytes = {0x9B, 0x9C, 0x9D, 0x9F};
const string Mathematics = "⌐¬½¼∧∞∮ϕ∈∩≡±≥≤⌠⌡÷≈√ⁿ²³";
readonly byte[] MathematicsBytes = { 0xA9, 0xAA, 0xAB, 0xAC, 0xDE, 0xDF, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xFB, 0xFC,
0xFD, 0xFE};
readonly byte[] MathematicsBytes =
{
0xA9, 0xAA, 0xAB, 0xAC, 0xDE, 0xDF, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xFB, 0xFC, 0xFD, 0xFE
};
const string Symbols = "⇧⇩⇨⇦❎✓♪ə";
readonly byte[] SymbolsBytes = {0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x0B, 0x1A};
[Test]
public void AtariSTPangrams()
{
byte[] byteArray;
string testString;
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Basque);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Basque, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Danish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Danish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.English);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.English, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Finnish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Finnish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.French);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.French, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Galician);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Galician, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.German);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.German, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Hebrew);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Hebrew, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Norwegian);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Norwegian, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Portuguese);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Portuguese, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Spanish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Spanish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Swedish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Swedish, testString);
}
[Test]
public void AtariSTToUnicode()
{
string testString;
testString = Encoding.AtariSTEncoding.GetString(PunctuationsBytes);
Assert.AreEqual(Punctuations, testString);
testString = Encoding.AtariSTEncoding.GetString(DigitsBytes);
Assert.AreEqual(Digits, testString);
testString = Encoding.AtariSTEncoding.GetString(UpperLatinBytes);
Assert.AreEqual(UpperLatin, testString);
testString = Encoding.AtariSTEncoding.GetString(LowerLatinBytes);
Assert.AreEqual(LowerLatin, testString);
testString = Encoding.AtariSTEncoding.GetString(SpanishBytes);
Assert.AreEqual(Spanish, testString);
testString = Encoding.AtariSTEncoding.GetString(FrenchBytes);
Assert.AreEqual(French, testString);
testString = Encoding.AtariSTEncoding.GetString(GermanBytes);
Assert.AreEqual(German, testString);
testString = Encoding.AtariSTEncoding.GetString(NorwegianBytes);
Assert.AreEqual(Norwegian, testString);
testString = Encoding.AtariSTEncoding.GetString(PortugueseBytes);
Assert.AreEqual(Portuguese, testString);
testString = Encoding.AtariSTEncoding.GetString(DutchBytes);
Assert.AreEqual(Dutch, testString);
testString = Encoding.AtariSTEncoding.GetString(HebrewBytes);
Assert.AreEqual(Hebrew, testString);
testString = Encoding.AtariSTEncoding.GetString(GreekBytes);
Assert.AreEqual(Greek, testString);
testString = Encoding.AtariSTEncoding.GetString(TypographicBytes);
Assert.AreEqual(Typographic, testString);
testString = Encoding.AtariSTEncoding.GetString(CurrencyBytes);
Assert.AreEqual(Currency, testString);
testString = Encoding.AtariSTEncoding.GetString(MathematicsBytes);
Assert.AreEqual(Mathematics, testString);
testString = Encoding.AtariSTEncoding.GetString(SymbolsBytes);
Assert.AreEqual(Symbols, testString);
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
/*testString = Encoding.AtariSTEncoding.GetString(SymbolsUnicode32Bytes);
Assert.AreEqual(SymbolsUnicode32, testString);*/
}
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
/*const string SymbolsUnicode32 = "\ud83d\udd52\ud83d\udd14";
readonly byte[] SymbolsUnicode32Bytes = { 0x09, 0x0A };*/
@@ -118,93 +226,5 @@ namespace Claunia.Encoding.Tests
/*byteArray = Encoding.AtariSTEncoding.GetBytes(SymbolsUnicode32);
Assert.AreEqual(SymbolsUnicode32Bytes, byteArray);*/
}
[Test]
public void AtariSTToUnicode()
{
string testString;
testString = Encoding.AtariSTEncoding.GetString(PunctuationsBytes);
Assert.AreEqual(Punctuations, testString);
testString = Encoding.AtariSTEncoding.GetString(DigitsBytes);
Assert.AreEqual(Digits, testString);
testString = Encoding.AtariSTEncoding.GetString(UpperLatinBytes);
Assert.AreEqual(UpperLatin, testString);
testString = Encoding.AtariSTEncoding.GetString(LowerLatinBytes);
Assert.AreEqual(LowerLatin, testString);
testString = Encoding.AtariSTEncoding.GetString(SpanishBytes);
Assert.AreEqual(Spanish, testString);
testString = Encoding.AtariSTEncoding.GetString(FrenchBytes);
Assert.AreEqual(French, testString);
testString = Encoding.AtariSTEncoding.GetString(GermanBytes);
Assert.AreEqual(German, testString);
testString = Encoding.AtariSTEncoding.GetString(NorwegianBytes);
Assert.AreEqual(Norwegian, testString);
testString = Encoding.AtariSTEncoding.GetString(PortugueseBytes);
Assert.AreEqual(Portuguese, testString);
testString = Encoding.AtariSTEncoding.GetString(DutchBytes);
Assert.AreEqual(Dutch, testString);
testString = Encoding.AtariSTEncoding.GetString(HebrewBytes);
Assert.AreEqual(Hebrew, testString);
testString = Encoding.AtariSTEncoding.GetString(GreekBytes);
Assert.AreEqual(Greek, testString);
testString = Encoding.AtariSTEncoding.GetString(TypographicBytes);
Assert.AreEqual(Typographic, testString);
testString = Encoding.AtariSTEncoding.GetString(CurrencyBytes);
Assert.AreEqual(Currency, testString);
testString = Encoding.AtariSTEncoding.GetString(MathematicsBytes);
Assert.AreEqual(Mathematics, testString);
testString = Encoding.AtariSTEncoding.GetString(SymbolsBytes);
Assert.AreEqual(Symbols, testString);
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
/*testString = Encoding.AtariSTEncoding.GetString(SymbolsUnicode32Bytes);
Assert.AreEqual(SymbolsUnicode32, testString);*/
}
[Test]
public void AtariSTPangrams()
{
byte[] byteArray;
string testString;
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Basque);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Basque, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Danish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Danish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.English);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.English, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Finnish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Finnish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.French);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.French, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Galician);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Galician, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.German);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.German, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Hebrew);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Hebrew, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Norwegian);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Norwegian, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Portuguese);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Portuguese, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Spanish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Spanish, testString);
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Swedish);
testString = Encoding.AtariSTEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Swedish, testString);
}
}
}

View File

@@ -23,6 +23,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
@@ -53,18 +54,18 @@ namespace Claunia.Encoding.Tests
}
}
[Test]
// Well basically this is taken from MSDN's documentation :p
public void GetInternalEncoding()
{
System.Text.Encoding e = Encoding.GetEncoding("lisa");
}
[Test]
// Well basically this is taken from MSDN's documentation :p
public void GetExternalEncoding()
{
System.Text.Encoding e = Encoding.GetEncoding("shift_jis");
}
[Test]
// Well basically this is taken from MSDN's documentation :p
public void GetInternalEncoding()
{
System.Text.Encoding e = Encoding.GetEncoding("lisa");
}
}
}

View File

@@ -32,100 +32,56 @@ namespace Claunia.Encoding.Tests
public class LisaRoman
{
const string Punctuations = "!\"#$%&()*+,-./:;<=>?@[\\]^_{|}~";
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7B, 0x7C, 0x7D, 0x7E };
readonly byte[] PunctuationsBytes =
{
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D,
0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7B, 0x7C, 0x7D, 0x7E
};
const string Digits = "0123456789";
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
readonly byte[] UpperLatinBytes =
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
};
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
readonly byte[] LowerLatinBytes =
{
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
};
const string Spanish = "¡¿áéíóúüñÉÜÑ";
readonly byte[] SpanishBytes = {0xC1, 0xC0, 0x87, 0x8E, 0x92, 0x97, 0x9C, 0x9F, 0x96, 0x83, 0x86, 0x84};
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
readonly byte[] FrenchBytes = { 0x8E, 0x83, 0x88, 0x8F, 0x9D, 0xCB, 0x89, 0x90, 0x94, 0x99, 0x9E, 0x91, 0x95, 0x9F, 0xD8, 0x8D, 0x82, 0xCF, 0xCE, 0xBE, 0xAE };
readonly byte[] FrenchBytes =
{
0x8E, 0x83, 0x88, 0x8F, 0x9D, 0xCB, 0x89, 0x90, 0x94, 0x99, 0x9E, 0x91, 0x95, 0x9F, 0xD8, 0x8D, 0x82, 0xCF,
0xCE, 0xBE, 0xAE
};
const string German = "äöüßÄÖÜ";
readonly byte[] GermanBytes = {0x8A, 0x9A, 0x9F, 0xA7, 0x80, 0x85, 0x86};
const string Norwegian = "æøåÆØÅ";
readonly byte[] NorwegianBytes = {0xBE, 0xBF, 0x8C, 0xAE, 0xAF, 0x81};
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
readonly byte[] PortugueseBytes = { 0x87, 0x8E, 0x92, 0x97, 0x9C, 0x83, 0x89, 0x90, 0x99, 0x8B, 0x9B, 0xCC, 0xCD, 0x8D, 0x82 };
readonly byte[] PortugueseBytes =
{0x87, 0x8E, 0x92, 0x97, 0x9C, 0x83, 0x89, 0x90, 0x99, 0x8B, 0x9B, 0xCC, 0xCD, 0x8D, 0x82};
const string Typographic = "†°•¶®©™´¨ªº«»…–—“”‘’§";
readonly byte[] TypographicBytes = { 0xA0, 0xA1, 0xA5, 0xA6, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xBB, 0xBC, 0xC7, 0xC8, 0xC9, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xA4};
readonly byte[] TypographicBytes =
{
0xA0, 0xA1, 0xA5, 0xA6, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xBB, 0xBC, 0xC7, 0xC8, 0xC9, 0xD0, 0xD1, 0xD2, 0xD3,
0xD4, 0xD5, 0xA4
};
const string Currency = "¢£¥";
readonly byte[] CurrencyBytes = {0xA2, 0xA3, 0xB4};
const string Mathematics = "≠∞±≤≥µ∂∑∏π∫Ω¬√ƒ≈∆÷◊";
readonly byte[] MathematicsBytes = { 0xAD, 0xB0, 0xB1, 0xB2, 0xB3, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBD, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xD6, 0xD7 };
[Test]
public void UnicodeToLisa()
readonly byte[] MathematicsBytes =
{
byte[] byteArray;
byteArray = Encoding.LisaEncoding.GetBytes(Punctuations);
Assert.AreEqual(PunctuationsBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Digits);
Assert.AreEqual(DigitsBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(UpperLatin);
Assert.AreEqual(UpperLatinBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(LowerLatin);
Assert.AreEqual(LowerLatinBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Spanish);
Assert.AreEqual(SpanishBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(French);
Assert.AreEqual(FrenchBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(German);
Assert.AreEqual(GermanBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Norwegian);
Assert.AreEqual(NorwegianBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Portuguese);
Assert.AreEqual(PortugueseBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Typographic);
Assert.AreEqual(TypographicBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Currency);
Assert.AreEqual(CurrencyBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Mathematics);
Assert.AreEqual(MathematicsBytes, byteArray);
}
[Test]
public void LisaToUnicode()
{
string testString;
testString = Encoding.LisaEncoding.GetString(PunctuationsBytes);
Assert.AreEqual(Punctuations, testString);
testString = Encoding.LisaEncoding.GetString(DigitsBytes);
Assert.AreEqual(Digits, testString);
testString = Encoding.LisaEncoding.GetString(UpperLatinBytes);
Assert.AreEqual(UpperLatin, testString);
testString = Encoding.LisaEncoding.GetString(LowerLatinBytes);
Assert.AreEqual(LowerLatin, testString);
testString = Encoding.LisaEncoding.GetString(SpanishBytes);
Assert.AreEqual(Spanish, testString);
testString = Encoding.LisaEncoding.GetString(FrenchBytes);
Assert.AreEqual(French, testString);
testString = Encoding.LisaEncoding.GetString(GermanBytes);
Assert.AreEqual(German, testString);
testString = Encoding.LisaEncoding.GetString(NorwegianBytes);
Assert.AreEqual(Norwegian, testString);
testString = Encoding.LisaEncoding.GetString(PortugueseBytes);
Assert.AreEqual(Portuguese, testString);
testString = Encoding.LisaEncoding.GetString(TypographicBytes);
Assert.AreEqual(Typographic, testString);
testString = Encoding.LisaEncoding.GetString(CurrencyBytes);
Assert.AreEqual(Currency, testString);
testString = Encoding.LisaEncoding.GetString(MathematicsBytes);
Assert.AreEqual(Mathematics, testString);
}
0xAD, 0xB0, 0xB1, 0xB2, 0xB3, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBD, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xD6,
0xD7
};
[Test]
public void LisaPangrams()
@@ -173,5 +129,71 @@ namespace Claunia.Encoding.Tests
testString = Encoding.LisaEncoding.GetString(byteArray);
Assert.AreEqual(Pangrams.Swedish, testString);
}
[Test]
public void LisaToUnicode()
{
string testString;
testString = Encoding.LisaEncoding.GetString(PunctuationsBytes);
Assert.AreEqual(Punctuations, testString);
testString = Encoding.LisaEncoding.GetString(DigitsBytes);
Assert.AreEqual(Digits, testString);
testString = Encoding.LisaEncoding.GetString(UpperLatinBytes);
Assert.AreEqual(UpperLatin, testString);
testString = Encoding.LisaEncoding.GetString(LowerLatinBytes);
Assert.AreEqual(LowerLatin, testString);
testString = Encoding.LisaEncoding.GetString(SpanishBytes);
Assert.AreEqual(Spanish, testString);
testString = Encoding.LisaEncoding.GetString(FrenchBytes);
Assert.AreEqual(French, testString);
testString = Encoding.LisaEncoding.GetString(GermanBytes);
Assert.AreEqual(German, testString);
testString = Encoding.LisaEncoding.GetString(NorwegianBytes);
Assert.AreEqual(Norwegian, testString);
testString = Encoding.LisaEncoding.GetString(PortugueseBytes);
Assert.AreEqual(Portuguese, testString);
testString = Encoding.LisaEncoding.GetString(TypographicBytes);
Assert.AreEqual(Typographic, testString);
testString = Encoding.LisaEncoding.GetString(CurrencyBytes);
Assert.AreEqual(Currency, testString);
testString = Encoding.LisaEncoding.GetString(MathematicsBytes);
Assert.AreEqual(Mathematics, testString);
}
[Test]
public void UnicodeToLisa()
{
byte[] byteArray;
byteArray = Encoding.LisaEncoding.GetBytes(Punctuations);
Assert.AreEqual(PunctuationsBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Digits);
Assert.AreEqual(DigitsBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(UpperLatin);
Assert.AreEqual(UpperLatinBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(LowerLatin);
Assert.AreEqual(LowerLatinBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Spanish);
Assert.AreEqual(SpanishBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(French);
Assert.AreEqual(FrenchBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(German);
Assert.AreEqual(GermanBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Norwegian);
Assert.AreEqual(NorwegianBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Portuguese);
Assert.AreEqual(PortugueseBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Typographic);
Assert.AreEqual(TypographicBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Currency);
Assert.AreEqual(CurrencyBytes, byteArray);
byteArray = Encoding.LisaEncoding.GetBytes(Mathematics);
Assert.AreEqual(MathematicsBytes, byteArray);
}
}
}

View File

@@ -494,7 +494,8 @@ namespace Claunia.Encoding
for(int i = 0; i < 256; i++)
// TODO: convert this to a gigantic switch statement too?
if(PETSCIITable[i] == character) return (byte)i;
if(PETSCIITable[i] == character)
return (byte)i;
// Fallback to '?'
return 0x3F;

View File

@@ -68,12 +68,10 @@ namespace Claunia.Encoding
public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis.";
/// <summary>A pangram that contains all (or most) Finnish characters.</summary>
public const string Finnish =
"Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta."
;
"Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta.";
/// <summary>A pangram that contains all (or most) French characters.</summary>
public const string French =
"Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ."
;
"Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ.";
/// <summary>A pangram that contains all (or most) Galician characters.</summary>
public const string Galician =
"Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente.";
@@ -81,12 +79,10 @@ namespace Claunia.Encoding
public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.";
/// <summary>A pangram that contains all (or most) Greek characters.</summary>
public const string Greek =
"Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós."
;
"Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós.";
/// <summary>A pangram that contains all (or most) Hebrew characters.</summary>
public const string Hebrew =
"לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ"
;
"לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ";
/// <summary>A pangram that contains all (or most) Hungarian characters.</summary>
public const string Hungarian = "Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít.";
/// <summary>A pangram that contains all (or most) Icelandic characters.</summary>
@@ -111,8 +107,7 @@ namespace Claunia.Encoding
public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!";
/// <summary>A pangram that contains all (or most) Portuguese characters.</summary>
public const string Portuguese =
"À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz."
;
"À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz.";
/// <summary>A pangram that contains all (or most) Romanian characters.</summary>
public const string Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila.";
/// <summary>A pangram that contains all (or most) Russian characters.</summary>
@@ -129,8 +124,7 @@ namespace Claunia.Encoding
public const string Slovenian = "Besni dirkač iz formule žuga cehu poštarjev.";
/// <summary>A pangram that contains all (or most) Spanish characters.</summary>
public const string Spanish =
"El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja."
;
"El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja.";
/// <summary>A pangram that contains all (or most) Swedish characters.</summary>
public const string Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor.";
/// <summary>A pangram that contains all (or most) Turkish characters.</summary>

View File

@@ -25,8 +25,8 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
@@ -51,4 +51,3 @@ using System.Runtime.CompilerServices;
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@@ -414,7 +414,8 @@ namespace Claunia.Encoding
outPos++;
break;
case 2:
rd50 = (byte)(((bytes[index + i - 1] & 0x0F) << 2) + ((bytes[index + i] & 0xC0) >> 6));
rd50 =
(byte)(((bytes[index + i - 1] & 0x0F) << 2) + ((bytes[index + i] & 0xC0) >> 6));
chars[outPos] = GetChar(rd50);
chars[outPos + 1] = GetChar((byte)(bytes[index + i] & 0x3F));
outPos += 2;