...

Source file src/github.com/logrusorgru/aurora/v3/color_test.go

Documentation: github.com/logrusorgru/aurora/v3

     1  //
     2  // Copyright (c) 2016-2020 The Aurora Authors. All rights reserved.
     3  // This program is free software. It comes without any warranty,
     4  // to the extent permitted by applicable law. You can redistribute
     5  // it and/or modify it under the terms of the Unlicense. See LICENSE
     6  // file for more details or see below.
     7  //
     8  
     9  //
    10  // This is free and unencumbered software released into the public domain.
    11  //
    12  // Anyone is free to copy, modify, publish, use, compile, sell, or
    13  // distribute this software, either in source code form or as a compiled
    14  // binary, for any purpose, commercial or non-commercial, and by any
    15  // means.
    16  //
    17  // In jurisdictions that recognize copyright laws, the author or authors
    18  // of this software dedicate any and all copyright interest in the
    19  // software to the public domain. We make this dedication for the benefit
    20  // of the public at large and to the detriment of our heirs and
    21  // successors. We intend this dedication to be an overt act of
    22  // relinquishment in perpetuity of all present and future rights to this
    23  // software under copyright law.
    24  //
    25  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    26  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    27  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    28  // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    29  // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    30  // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    31  // OTHER DEALINGS IN THE SOFTWARE.
    32  //
    33  // For more information, please refer to <http://unlicense.org/>
    34  //
    35  
    36  package aurora
    37  
    38  import (
    39  	"strconv"
    40  	"testing"
    41  )
    42  
    43  func TestColor_Nos(t *testing.T) {
    44  
    45  	for _, zero := range []bool{
    46  		false, true,
    47  	} {
    48  		for i, val := range []struct {
    49  			Nos   string
    50  			Color Color
    51  		}{
    52  			{"1", BoldFm},
    53  			{"2", FaintFm},
    54  			{"3", ItalicFm},
    55  			{"4", UnderlineFm},
    56  			{"5", SlowBlinkFm},
    57  			{"6", RapidBlinkFm},
    58  			{"7", ReverseFm},
    59  			{"8", ConcealFm},
    60  			{"9", CrossedOutFm},
    61  
    62  			{"20", FrakturFm},
    63  			{"21", DoublyUnderlineFm},
    64  
    65  			{"51", FramedFm},
    66  			{"52", EncircledFm},
    67  			{"53", OverlinedFm},
    68  
    69  			{"30", BlackFg},
    70  			{"31", RedFg},
    71  			{"32", GreenFg},
    72  			{"33", YellowFg},
    73  			{"34", BlueFg},
    74  			{"35", MagentaFg},
    75  			{"36", CyanFg},
    76  			{"37", WhiteFg},
    77  
    78  			{"90", BlackFg | BrightFg},
    79  			{"91", RedFg | BrightFg},
    80  			{"92", GreenFg | BrightFg},
    81  			{"93", YellowFg | BrightFg},
    82  			{"94", BlueFg | BrightFg},
    83  			{"95", MagentaFg | BrightFg},
    84  			{"96", CyanFg | BrightFg},
    85  			{"97", WhiteFg | BrightFg},
    86  
    87  			{"90", BrightFg},
    88  
    89  			{"40", BlackBg},
    90  			{"41", RedBg},
    91  			{"42", GreenBg},
    92  			{"43", YellowBg},
    93  			{"44", BlueBg},
    94  			{"45", MagentaBg},
    95  			{"46", CyanBg},
    96  			{"47", WhiteBg},
    97  
    98  			{"100", BlackBg | BrightBg},
    99  			{"101", RedBg | BrightBg},
   100  			{"102", GreenBg | BrightBg},
   101  			{"103", YellowBg | BrightBg},
   102  			{"104", BlueBg | BrightBg},
   103  			{"105", MagentaBg | BrightBg},
   104  			{"106", CyanBg | BrightBg},
   105  			{"107", WhiteBg | BrightBg},
   106  
   107  			{"100", BrightBg},
   108  
   109  			// bold and faint
   110  
   111  			{"1", BoldFm | FaintFm},
   112  
   113  			// slow blink and rapid blink
   114  
   115  			{"5", SlowBlinkFm | RapidBlinkFm},
   116  
   117  			// index
   118  
   119  			{"38;5;100", (100 << shiftFg) | flagFg},
   120  			{"48;5;100", (100 << shiftBg) | flagBg},
   121  
   122  			// longest combination
   123  
   124  			{"1;3;4;5;7;8;9;20;21;51;52;53;38;5;123;48;5;231",
   125  				BoldFm | FaintFm |
   126  					ItalicFm | UnderlineFm |
   127  					SlowBlinkFm | RapidBlinkFm |
   128  					ReverseFm | ConcealFm |
   129  					CrossedOutFm | FrakturFm | DoublyUnderlineFm |
   130  					FramedFm | EncircledFm | OverlinedFm |
   131  					Color(123)<<shiftFg | flagFg |
   132  					Color(231)<<shiftBg | flagBg},
   133  		} {
   134  			var (
   135  				nos  = val.Color.Nos(zero)
   136  				want = val.Nos
   137  			)
   138  			if zero {
   139  				if want != "" {
   140  					want = "0;" + want
   141  				} else {
   142  					want = "0"
   143  				}
   144  			}
   145  			if nos != want {
   146  				t.Errorf("%t %d: wrong nos string %q, want %q",
   147  					zero, i, nos, want)
   148  			}
   149  		}
   150  	}
   151  }
   152  
   153  func TestColor_IsValid(t *testing.T) {
   154  	if Color(0).IsValid() == false {
   155  		t.Error("invalid")
   156  	}
   157  }
   158  
   159  func Test_itoa(t *testing.T) {
   160  	for i := 0; i < 256; i++ {
   161  		if a := itoa(byte(i)); a != strconv.Itoa(i) {
   162  			t.Errorf("wrong %q, want %d", a, i)
   163  		}
   164  	}
   165  }
   166  

View as plain text