summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexers/jvm.py2
-rw-r--r--tests/test_java.py42
2 files changed, 43 insertions, 1 deletions
diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py
index 86a45d1e..136a0fd7 100644
--- a/pygments/lexers/jvm.py
+++ b/pygments/lexers/jvm.py
@@ -62,7 +62,7 @@ class JavaLexer(RegexLexer):
(r'"(\\\\|\\"|[^"])*"', String),
(r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
(r'(\.)((?:[^\W\d]|\$)[\w\$]*)', bygroups(Operator, Name.Attribute)),
- (r'([^\W\d]|\$)[\w\$]*:', Name.Label),
+ (r'^\s*([^\W\d]|\$)[\w\$]*:', Name.Label),
(r'([^\W\d]|\$)[\w\$]*', Name),
(r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
diff --git a/tests/test_java.py b/tests/test_java.py
new file mode 100644
index 00000000..9cf96373
--- /dev/null
+++ b/tests/test_java.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+"""
+ Basic JavaLexer Test
+ ~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import unittest
+
+from pygments.token import Text, Name, Operator, Keyword
+from pygments.lexers import JavaLexer
+
+
+class JavaTest(unittest.TestCase):
+
+ def setUp(self):
+ self.lexer = JavaLexer()
+ self.maxDiff = None
+
+ def testEnhancedFor(self):
+ fragment = u'label:\nfor(String var2: var1) {}\n'
+ tokens = [
+ (Name.Label, u'label:'),
+ (Text, u'\n'),
+ (Keyword, u'for'),
+ (Operator, u'('),
+ (Name, u'String'),
+ (Text, u' '),
+ (Name, u'var2'),
+ (Operator, u':'),
+ (Text, u' '),
+ (Name, u'var1'),
+ (Operator, u')'),
+ (Text, u' '),
+ (Operator, u'{'),
+ (Operator, u'}'),
+ (Text, u'\n'),
+ ]
+ self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+