// // Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. // This program is free software. It comes without any warranty, // to the extent permitted by applicable law. You can redistribute // it and/or modify it under the terms of the Unlicense. See LICENSE // file for more details or see below. // // // This is free and unencumbered software released into the public domain. // // Anyone is free to copy, modify, publish, use, compile, sell, or // distribute this software, either in source code form or as a compiled // binary, for any purpose, commercial or non-commercial, and by any // means. // // In jurisdictions that recognize copyright laws, the author or authors // of this software dedicate any and all copyright interest in the // software to the public domain. We make this dedication for the benefit // of the public at large and to the detriment of our heirs and // successors. We intend this dedication to be an overt act of // relinquishment in perpetuity of all present and future rights to this // software under copyright law. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // For more information, please refer to // package aurora import ( "fmt" "testing" ) func TestValue_String(t *testing.T) { var v Value // colorized v = value{"x", 0, 0} if x := v.String(); x != "x" { t.Errorf("(value).String: want %q, got %q", "x", x) } v = value{"x", BlackFg, RedBg} want := "\033[0;30mx\033[0;41m" if got := v.String(); want != got { t.Errorf("(value).String: want %q, got %q", want, got) } // clear v = valueClear{"x"} if x := v.String(); x != "x" { t.Errorf("(value).String: want %q, got %q", "x", x) } } func TestValue_Color(t *testing.T) { // colorized if (value{"", RedFg, 0}).Color() != RedFg { t.Error("wrong color") } // clear if (valueClear{0}).Color() != 0 { t.Error("wrong color") } } func TestValue_Value(t *testing.T) { // colorized if (value{"x", RedFg, BlueBg}).Value() != "x" { t.Error("wrong value") } // clear if (valueClear{"x"}).Value() != "x" { t.Error("wrong value") } } func TestValue_Bleach(t *testing.T) { // colorized if (value{"x", RedFg, BlueBg}).Bleach() != (value{value: "x"}) { t.Error("wrong bleached") } // clear if (valueClear{"x"}).Bleach() != (valueClear{"x"}) { t.Error("wrong bleached") } } func TestValue_Format(t *testing.T) { var v Value var want, got string // // colorized // v = value{3.14, RedFg, BlueBg} got = fmt.Sprintf("%+1.3g", v) want = "\033[0;31m" + fmt.Sprintf("%+1.3g", 3.14) + "\033[0;44m" if want != got { t.Errorf("Format: want %q, got %q", want, got) } // var utf8Verb = "%+1.3δΈ–" // verb that fit more then 1 byte got = fmt.Sprintf(utf8Verb, v) want = "\033[0;31m" + fmt.Sprintf(utf8Verb, 3.14) + "\033[0;44m" if want != got { t.Errorf("Format: want %q, got %q", want, got) } // // clear // v = valueClear{3.14} got = fmt.Sprintf("%+1.3g", v) want = fmt.Sprintf("%+1.3g", 3.14) if want != got { t.Errorf("Format: want %q, got %q", want, got) } // got = fmt.Sprintf(utf8Verb, v) want = fmt.Sprintf(utf8Verb, 3.14) if want != got { t.Errorf("Format: want %q, got %q", want, got) } } func Test_tail(t *testing.T) { // colorized if (value{"x", 0, BlueBg}).tail() != BlueBg { t.Error("wrong tail color") } // clear if (valueClear{"x"}).tail() != 0 { t.Error("wrong tail color") } } func Test_setTail(t *testing.T) { // colorized if (value{"x", 0, 0}).setTail(RedFg) != (value{"x", 0, RedFg}) { t.Error("wrong setTail behavior") } // clear if (valueClear{"x"}).setTail(RedFg) != (valueClear{"x"}) { t.Error("wrong setTail behavior") } } func TestValue_colors(t *testing.T) { test := func(name string, v Value, clr Color) { t.Helper() if c := v.Color(); c != clr { t.Errorf("wrong color for %s: want %d, got %d", name, clr, c) } } // colorized test("Reset", Reset("x"), 0) test("Bold", Bold("x"), BoldFm) test("Faint", Faint("x"), FaintFm) test("DoublyUnderline", DoublyUnderline("x"), DoublyUnderlineFm) test("Fraktur & Yellow", Yellow(Fraktur("x")), FrakturFm|YellowFg) test("Italic", Italic("x"), ItalicFm) test("Underline", Underline("x"), UnderlineFm) test("SlowBlink", SlowBlink("x"), SlowBlinkFm) test("RapidBlink", RapidBlink("x"), RapidBlinkFm) test("Blink", Blink("x"), BlinkFm) test("Reverse", Reverse("x"), ReverseFm) test("Inverse", Inverse("x"), InverseFm) test("Conceal", Conceal("x"), ConcealFm) test("Hidden", Hidden("x"), HiddenFm) test("CrossedOut", CrossedOut("x"), CrossedOutFm) test("StrikeThrough", StrikeThrough("x"), StrikeThroughFm) test("Framed", Framed("x"), FramedFm) test("Encircled", Encircled("x"), EncircledFm) test("Overlined", Overlined("x"), OverlinedFm) test("Black", Black("x"), BlackFg) test("Red", Red("x"), RedFg) test("Green", Green("x"), GreenFg) test("Yellow", Yellow("x"), YellowFg) test("Brown", Brown("x"), BrownFg) test("Blue", Blue("x"), BlueFg) test("Magenta", Magenta("x"), MagentaFg) test("Cyan", Cyan("x"), CyanFg) test("White", White("x"), WhiteFg) test("BrightBlack", BrightBlack("x"), BrightFg|BlackFg) test("BrightRed", BrightRed("x"), BrightFg|RedFg) test("BrightGreen", BrightGreen("x"), BrightFg|GreenFg) test("BrightYellow", BrightYellow("x"), BrightFg|YellowFg) test("BrightBlue", BrightBlue("x"), BrightFg|BlueFg) test("BrightMagenta", BrightMagenta("x"), BrightFg|MagentaFg) test("BrightCyan", BrightCyan("x"), BrightFg|CyanFg) test("BrightWhite", BrightWhite("x"), BrightFg|WhiteFg) test("Index", Index(178, "x"), (Color(178)<