public void Detect_encoding_for_HTML_file_without_meta()
 {
     const string resource = "html-bom-utf8.txt";
     using(var stream = GetResourceStream(resource)) {
         var detector = new HtmlMetaEncodingDetector();
         var encoding = detector.Detect(stream);
         var offset = stream.Position;
         Assert.IsNull(encoding, "encoding detection failed");
     }
 }
Beispiel #2
0
        public void Detect_encoding_for_HTML_file_with_Windows1252()
        {
            const string resource = "html-meta-windows-1252.txt";
            using(var stream = GetResourceStream(resource)) {
                var detector = new HtmlMetaEncodingDetector();
                var encoding = detector.Detect(stream);
                var offset = stream.Position;
                Assert.IsNotNull(encoding, "encoding detection failed");
                Assert.AreEqual(0, offset, "wrong stream position");

                string text;
                using(var reader = new StreamReader(stream, encoding)) {
                    text = reader.ReadToEnd();
                }

                Assert.AreEqual("Western European (Windows)", encoding.EncodingName);
                AssertEncoding(text, resource, Encoding.GetEncoding("Windows-1252"), offset);
                _log.DebugFormat("Detected encoding: {0}", encoding.EncodingName);
            }
        }