Index: /pyyaml/trunk/tests/lib/test_representer.py
===================================================================
--- /pyyaml/trunk/tests/lib/test_representer.py	(revision 330)
+++ /pyyaml/trunk/tests/lib/test_representer.py	(revision 351)
@@ -7,31 +7,32 @@
     test_constructor._make_objects()
     for allow_unicode in [False, True]:
-        native1 = test_constructor._load_code(open(code_filename, 'rb').read())
-        native2 = None
-        try:
-            output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
-                        allow_unicode=allow_unicode)
-            native2 = yaml.load(output, Loader=test_constructor.MyLoader)
+        for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
+            native1 = test_constructor._load_code(open(code_filename, 'rb').read())
+            native2 = None
             try:
-                if native1 == native2:
-                    continue
-            except TypeError:
-                pass
-            value1 = test_constructor._serialize_value(native1)
-            value2 = test_constructor._serialize_value(native2)
-            if verbose:
-                print "SERIALIZED NATIVE1:"
-                print value1
-                print "SERIALIZED NATIVE2:"
-                print value2
-            assert value1 == value2, (native1, native2)
-        finally:
-            if verbose:
-                print "NATIVE1:"
-                pprint.pprint(native1)
-                print "NATIVE2:"
-                pprint.pprint(native2)
-                print "OUTPUT:"
-                print output
+                output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
+                            allow_unicode=allow_unicode, encoding=encoding)
+                native2 = yaml.load(output, Loader=test_constructor.MyLoader)
+                try:
+                    if native1 == native2:
+                        continue
+                except TypeError:
+                    pass
+                value1 = test_constructor._serialize_value(native1)
+                value2 = test_constructor._serialize_value(native2)
+                if verbose:
+                    print "SERIALIZED NATIVE1:"
+                    print value1
+                    print "SERIALIZED NATIVE2:"
+                    print value2
+                assert value1 == value2, (native1, native2)
+            finally:
+                if verbose:
+                    print "NATIVE1:"
+                    pprint.pprint(native1)
+                    print "NATIVE2:"
+                    pprint.pprint(native2)
+                    print "OUTPUT:"
+                    print output
 
 test_representer_types.unittest = ['.code']
Index: /pyyaml/trunk/tests/data/utf16be.code
===================================================================
--- /pyyaml/trunk/tests/data/utf16be.code	(revision 351)
+++ /pyyaml/trunk/tests/data/utf16be.code	(revision 351)
@@ -0,0 +1,1 @@
+"UTF-16-BE"
Index: /pyyaml/trunk/tests/data/utf8.data
===================================================================
--- /pyyaml/trunk/tests/data/utf8.data	(revision 351)
+++ /pyyaml/trunk/tests/data/utf8.data	(revision 351)
@@ -0,0 +1,1 @@
+﻿--- UTF-8
Index: /pyyaml/trunk/tests/data/utf8-implicit.data
===================================================================
--- /pyyaml/trunk/tests/data/utf8-implicit.data	(revision 351)
+++ /pyyaml/trunk/tests/data/utf8-implicit.data	(revision 351)
@@ -0,0 +1,1 @@
+--- implicit UTF-8
Index: /pyyaml/trunk/tests/data/utf8.code
===================================================================
--- /pyyaml/trunk/tests/data/utf8.code	(revision 351)
+++ /pyyaml/trunk/tests/data/utf8.code	(revision 351)
@@ -0,0 +1,1 @@
+"UTF-8"
Index: /pyyaml/trunk/tests/data/utf8-implicit.code
===================================================================
--- /pyyaml/trunk/tests/data/utf8-implicit.code	(revision 351)
+++ /pyyaml/trunk/tests/data/utf8-implicit.code	(revision 351)
@@ -0,0 +1,1 @@
+"implicit UTF-8"
Index: /pyyaml/trunk/tests/data/utf16le.code
===================================================================
--- /pyyaml/trunk/tests/data/utf16le.code	(revision 351)
+++ /pyyaml/trunk/tests/data/utf16le.code	(revision 351)
@@ -0,0 +1,1 @@
+"UTF-16-LE"
Index: /pyyaml/trunk/tests/lib3/test_representer.py
===================================================================
--- /pyyaml/trunk/tests/lib3/test_representer.py	(revision 330)
+++ /pyyaml/trunk/tests/lib3/test_representer.py	(revision 351)
@@ -7,31 +7,32 @@
     test_constructor._make_objects()
     for allow_unicode in [False, True]:
-        native1 = test_constructor._load_code(open(code_filename, 'rb').read())
-        native2 = None
-        try:
-            output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
-                        allow_unicode=allow_unicode)
-            native2 = yaml.load(output, Loader=test_constructor.MyLoader)
+        for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
+            native1 = test_constructor._load_code(open(code_filename, 'rb').read())
+            native2 = None
             try:
-                if native1 == native2:
-                    continue
-            except TypeError:
-                pass
-            value1 = test_constructor._serialize_value(native1)
-            value2 = test_constructor._serialize_value(native2)
-            if verbose:
-                print("SERIALIZED NATIVE1:")
-                print(value1)
-                print("SERIALIZED NATIVE2:")
-                print(value2)
-            assert value1 == value2, (native1, native2)
-        finally:
-            if verbose:
-                print("NATIVE1:")
-                pprint.pprint(native1)
-                print("NATIVE2:")
-                pprint.pprint(native2)
-                print("OUTPUT:")
-                print(output)
+                output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
+                            allow_unicode=allow_unicode, encoding=encoding)
+                native2 = yaml.load(output, Loader=test_constructor.MyLoader)
+                try:
+                    if native1 == native2:
+                        continue
+                except TypeError:
+                    pass
+                value1 = test_constructor._serialize_value(native1)
+                value2 = test_constructor._serialize_value(native2)
+                if verbose:
+                    print("SERIALIZED NATIVE1:")
+                    print(value1)
+                    print("SERIALIZED NATIVE2:")
+                    print(value2)
+                assert value1 == value2, (native1, native2)
+            finally:
+                if verbose:
+                    print("NATIVE1:")
+                    pprint.pprint(native1)
+                    print("NATIVE2:")
+                    pprint.pprint(native2)
+                    print("OUTPUT:")
+                    print(output)
 
 test_representer_types.unittest = ['.code']
Index: /pyyaml/trunk/lib/yaml/emitter.py
===================================================================
--- /pyyaml/trunk/lib/yaml/emitter.py	(revision 347)
+++ /pyyaml/trunk/lib/yaml/emitter.py	(revision 351)
@@ -790,5 +790,5 @@
         # Write BOM if needed.
         if self.encoding and self.encoding.startswith('utf-16'):
-            self.stream.write(u'\xFF\xFE'.encode(self.encoding))
+            self.stream.write(u'\uFEFF'.encode(self.encoding))
 
     def write_stream_end(self):
Index: /pyyaml/trunk/lib3/yaml/emitter.py
===================================================================
--- /pyyaml/trunk/lib3/yaml/emitter.py	(revision 329)
+++ /pyyaml/trunk/lib3/yaml/emitter.py	(revision 351)
@@ -786,5 +786,5 @@
         # Write BOM if needed.
         if self.encoding and self.encoding.startswith('utf-16'):
-            self.stream.write('\xFF\xFE'.encode(self.encoding))
+            self.stream.write('\uFEFF'.encode(self.encoding))
 
     def write_stream_end(self):
