encoding: added Replacement identifier and htmlindex tests

Adding the replacement type is useful for being able to roundtrip.
Albeit not strictly necessary, it makes the tests a bit nicer and
probably other things as well.

Change-Id: Ic85fb85cefa6116e64afb0b44923f878036592db
Reviewed-on: https://go-review.googlesource.com/17804
Reviewed-by: Andy Balholm <andy@balholm.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/encoding/encoding.go b/encoding/encoding.go
index 51fc9ef..2a7d952 100644
--- a/encoding/encoding.go
+++ b/encoding/encoding.go
@@ -16,6 +16,7 @@
 	"strconv"
 	"unicode/utf8"
 
+	"golang.org/x/text/encoding/internal/identifier"
 	"golang.org/x/text/transform"
 )
 
@@ -157,6 +158,10 @@
 	return &Encoder{Transformer: replacementEncoder{}}
 }
 
+func (replacement) ID() (mib identifier.MIB, other string) {
+	return identifier.Replacement, ""
+}
+
 type replacementDecoder struct{ transform.NopResetter }
 
 func (replacementDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
diff --git a/encoding/htmlindex/htmlindex_test.go b/encoding/htmlindex/htmlindex_test.go
index 7d83c85..3fdab0f 100644
--- a/encoding/htmlindex/htmlindex_test.go
+++ b/encoding/htmlindex/htmlindex_test.go
@@ -9,6 +9,7 @@
 
 	"golang.org/x/text/encoding"
 	"golang.org/x/text/encoding/charmap"
+	"golang.org/x/text/encoding/internal/identifier"
 	"golang.org/x/text/encoding/unicode"
 	"golang.org/x/text/language"
 )
@@ -39,6 +40,22 @@
 	}
 }
 
+func TestTables(t *testing.T) {
+	for name, index := range nameMap {
+		got, err := Get(name)
+		if err != nil {
+			t.Errorf("%s:err: expected non-nil error", name)
+		}
+		if want := encodings[index]; got != want {
+			t.Errorf("%s:encoding: got %v; want %v", name, got, want)
+		}
+		mib, _ := got.(identifier.Interface).ID()
+		if mibMap[mib] != index {
+			t.Errorf("%s:mibMab: got %d; want %d", name, mibMap[mib], index)
+		}
+	}
+}
+
 func TestName(t *testing.T) {
 	for i, tc := range []struct {
 		desc string
diff --git a/encoding/htmlindex/map.go b/encoding/htmlindex/map.go
index c3a146f..80cee23 100644
--- a/encoding/htmlindex/map.go
+++ b/encoding/htmlindex/map.go
@@ -57,6 +57,7 @@
 	identifier.ISO2022JP:         iso2022jp,
 	identifier.ShiftJIS:          shiftJIS,
 	identifier.EUCKR:             euckr,
+	identifier.Replacement:       replacement,
 }
 
 // encodings maps the internal htmlEncoding to an Encoding.
diff --git a/encoding/internal/identifier/identifier.go b/encoding/internal/identifier/identifier.go
index cfb1354..2a2da0e 100644
--- a/encoding/internal/identifier/identifier.go
+++ b/encoding/internal/identifier/identifier.go
@@ -70,7 +70,8 @@
 	// Unofficial marks the start of encodings not registered by IANA.
 	Unofficial MIB = 10000 + iota
 
-	// TODO: add Replacement?
+	// Replacement is the WhatWG replacement encoding.
+	Replacement
 
 	// XUserDefined is the code for x-user-defined.
 	XUserDefined