(t *testing.T)
| 1757 | } |
| 1758 | |
| 1759 | func TestSetTrustRawMessage(t *testing.T) { |
| 1760 | buf := &bytes.Buffer{} |
| 1761 | enc := NewEncoder(buf) |
| 1762 | enc.SetTrustRawMessage(true) |
| 1763 | |
| 1764 | // "Good" values are encoded in the regular way |
| 1765 | m := map[string]json.RawMessage{ |
| 1766 | "k": json.RawMessage(`"value"`), |
| 1767 | } |
| 1768 | if err := enc.Encode(m); err != nil { |
| 1769 | t.Error(err) |
| 1770 | } |
| 1771 | |
| 1772 | b := buf.Bytes() |
| 1773 | exp := []byte(`{"k":"value"}`) |
| 1774 | exp = append(exp, '\n') |
| 1775 | if !bytes.Equal(exp, b) { |
| 1776 | t.Error( |
| 1777 | "unexpected encoding:", |
| 1778 | "expected", exp, |
| 1779 | "got", b, |
| 1780 | ) |
| 1781 | } |
| 1782 | |
| 1783 | // "Bad" values are encoded without checking and throwing an error |
| 1784 | buf.Reset() |
| 1785 | m = map[string]json.RawMessage{ |
| 1786 | "k": json.RawMessage(`bad"value`), |
| 1787 | } |
| 1788 | if err := enc.Encode(m); err != nil { |
| 1789 | t.Error(err) |
| 1790 | } |
| 1791 | |
| 1792 | b = buf.Bytes() |
| 1793 | exp = []byte(`{"k":bad"value}`) |
| 1794 | exp = append(exp, '\n') |
| 1795 | if !bytes.Equal(exp, b) { |
| 1796 | t.Error( |
| 1797 | "unexpected encoding:", |
| 1798 | "expected", exp, |
| 1799 | "got", b, |
| 1800 | ) |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | func TestSetAppendNewline(t *testing.T) { |
| 1805 | buf := &bytes.Buffer{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…