don't get stuck in EventLog on malformed links
[idea/community.git] / platform / platform-tests / testSrc / com / intellij / notification / EventLogTest.groovy
1 /*
2  * Copyright 2000-2012 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.notification;
17
18
19 import com.intellij.openapi.util.TextRange
20 import com.intellij.testFramework.LightPlatformTestCase
21 import com.intellij.testFramework.PlatformTestCase
22
23 /**
24  * @author peter
25  */
26 class EventLogTest extends LightPlatformTestCase {
27
28   EventLogTest() {
29     PlatformTestCase.initPlatformLangPrefix()
30   }
31
32   public void testNbsp() {
33     def entry = EventLog.formatForLog(new Notification("xxx", "Title", "Hello world", NotificationType.ERROR))
34     assert entry.message == 'Title: Hello world'
35   }
36
37   public void testParseMultilineText() {
38     def entry = EventLog.formatForLog(new Notification("xxx", "Title", "<html><body> " +
39                                                                        "<font size=\"3\">first line<br>" +
40                                                                        "second line<br>" +
41                                                                        "third<br>" +
42                                                                        "<a href=\"create\">Action</a><br>" +
43                                                                        "</body></html>", NotificationType.ERROR))
44     assert entry.message == 'Title:  first line second line third // Action (show balloon)'
45     //                       0                                       40      48          60
46     assert entry.links.collect { it.first } == [new TextRange(40, 46), new TextRange(48, 60)]
47
48   }
49
50   public void testInParagraph() {
51     def entry = EventLog.formatForLog(new Notification("xxx", "Title", "<p>message</p>", NotificationType.ERROR))
52     assert entry.message == 'Title: message'
53   }
54
55   public void testJavaSeparators() {
56     def entry = EventLog.formatForLog(new Notification("xxx", "Title", "fst\nsnd", NotificationType.ERROR))
57     assert entry.message == 'Title: fst snd'
58   }
59
60   public void testLinkInTitle() {
61     def entry = EventLog.formatForLog(new Notification("xxx", '<a href="a">link</a>', "content", NotificationType.ERROR))
62     assert entry.message == 'link: content'
63     assert entry.links.collect { it.first } == [new TextRange(0, 4)]
64   }
65
66   public void testMalformedLink() throws Exception {
67     def entry = EventLog.formatForLog(new Notification("xxx", '<a href="a">link<a/>', "content", NotificationType.ERROR))
68     assert entry.message ==  'link: content (show balloon)'
69   }
70
71 }