#!/usr/bin/tclsh8.6

# Check that system and output encodings are set to UTF-8...
if {[encoding system] ne "utf-8"} {error !}
if {[fconfigure stdout -encoding] ne "utf-8"} {error !}

# A string containing a 2, 3 and 4 byte UTF-8 characters...
set string -á-✍-😃-

# This puts produces 8 bytes where the 4-byte charater should be!
puts $string

# This puts produces only 1 bytes where the 2 and 3 byte characters should be!
fconfigure stdout -encoding binary
puts $string

# This puts produces what we expected to get in the first place...
set string -[encoding convertto utf-8 á]-[encoding convertto utf-8 ✍]-😃-
puts $string
