|
| 1 | +// Copyright © 2019 The Homeport Team |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in |
| 11 | +// all copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | +// THE SOFTWARE. |
| 20 | + |
| 21 | +package neat_test |
| 22 | + |
| 23 | +import ( |
| 24 | + . "github.com/onsi/ginkgo" |
| 25 | + . "github.com/onsi/gomega" |
| 26 | + |
| 27 | + . "github.com/gonvenience/bunt" |
| 28 | + . "github.com/gonvenience/neat" |
| 29 | +) |
| 30 | + |
| 31 | +var _ = Describe("content box", func() { |
| 32 | + BeforeEach(func() { |
| 33 | + ColorSetting = ON |
| 34 | + TrueColorSetting = ON |
| 35 | + }) |
| 36 | + |
| 37 | + AfterEach(func() { |
| 38 | + ColorSetting = OFF |
| 39 | + TrueColorSetting = OFF |
| 40 | + }) |
| 41 | + |
| 42 | + Context("rendering content boxes", func() { |
| 43 | + var ( |
| 44 | + headline = "headline" |
| 45 | + content = `multi |
| 46 | +line |
| 47 | +content |
| 48 | +` |
| 49 | + ) |
| 50 | + |
| 51 | + It("should create a simply styled content box", func() { |
| 52 | + Expect("\n" + ContentBox(headline, content)).To(BeEquivalentTo(Sprintf(` |
| 53 | +╭ *headline* |
| 54 | +│ multi |
| 55 | +│ line |
| 56 | +│ content |
| 57 | +╵ |
| 58 | +`))) |
| 59 | + }) |
| 60 | + |
| 61 | + It("should create styled content box with headline colors", func() { |
| 62 | + Expect("\n" + ContentBox(headline, content, |
| 63 | + HeadlineColor(DodgerBlue), |
| 64 | + )).To(BeEquivalentTo(Sprintf(` |
| 65 | +DodgerBlue{╭ *headline*} |
| 66 | +DodgerBlue{│} multi |
| 67 | +DodgerBlue{│} line |
| 68 | +DodgerBlue{│} content |
| 69 | +DodgerBlue{╵} |
| 70 | +`))) |
| 71 | + }) |
| 72 | + |
| 73 | + It("should create styled content box with content colors", func() { |
| 74 | + Expect("\n" + ContentBox(headline, content, |
| 75 | + ContentColor(DimGray), |
| 76 | + )).To(BeEquivalentTo(Sprintf(` |
| 77 | +╭ *headline* |
| 78 | +│ DimGray{multi} |
| 79 | +│ DimGray{line} |
| 80 | +│ DimGray{content} |
| 81 | +╵ |
| 82 | +`))) |
| 83 | + }) |
| 84 | + |
| 85 | + It("should create styled content box with headline and content colors", func() { |
| 86 | + Expect("\n" + ContentBox(headline, content, |
| 87 | + HeadlineColor(DodgerBlue), |
| 88 | + ContentColor(DimGray), |
| 89 | + )).To(BeEquivalentTo(Sprintf(` |
| 90 | +DodgerBlue{╭ *headline*} |
| 91 | +DodgerBlue{│} DimGray{multi} |
| 92 | +DodgerBlue{│} DimGray{line} |
| 93 | +DodgerBlue{│} DimGray{content} |
| 94 | +DodgerBlue{╵} |
| 95 | +`))) |
| 96 | + }) |
| 97 | + }) |
| 98 | + |
| 99 | + Context("rendering content boxes with already colored content", func() { |
| 100 | + setupTestStrings := func() (string, string) { |
| 101 | + return Sprintf("CornflowerBlue{~headline~}"), |
| 102 | + Sprintf(`Red{*multi*} |
| 103 | +Green{_line_} |
| 104 | +Blue{~content~} |
| 105 | +`) |
| 106 | + } |
| 107 | + |
| 108 | + It("should preserve already existing colors and text emphasis", func() { |
| 109 | + headline, content := setupTestStrings() |
| 110 | + Expect("\n" + ContentBox(headline, content)).To(BeEquivalentTo(Sprintf(` |
| 111 | +╭ CornflowerBlue{*~headline~*} |
| 112 | +│ Red{*multi*} |
| 113 | +│ Green{_line_} |
| 114 | +│ Blue{~content~} |
| 115 | +╵ |
| 116 | +`))) |
| 117 | + }) |
| 118 | + |
| 119 | + It("should overwrite existing headline color if it is specified", func() { |
| 120 | + headline, content := setupTestStrings() |
| 121 | + Expect("\n" + ContentBox(headline, content, |
| 122 | + HeadlineColor(DimGray), |
| 123 | + )).To(BeEquivalentTo(Sprintf(` |
| 124 | +DimGray{╭ *~headline~*} |
| 125 | +DimGray{│} Red{*multi*} |
| 126 | +DimGray{│} Green{_line_} |
| 127 | +DimGray{│} Blue{~content~} |
| 128 | +DimGray{╵} |
| 129 | +`))) |
| 130 | + }) |
| 131 | + |
| 132 | + It("should overwrite existing content color if it is specified", func() { |
| 133 | + headline, content := setupTestStrings() |
| 134 | + Expect("\n" + ContentBox(headline, content, |
| 135 | + ContentColor(DimGray), |
| 136 | + )).To(BeEquivalentTo(Sprintf(` |
| 137 | +╭ CornflowerBlue{*~headline~*} |
| 138 | +│ DimGray{*multi*} |
| 139 | +│ DimGray{_line_} |
| 140 | +│ DimGray{~content~} |
| 141 | +╵ |
| 142 | +`))) |
| 143 | + }) |
| 144 | + }) |
| 145 | +}) |
0 commit comments