sb.append("private static void ").append(lengthCheckerName(member)).append("(final String value) {\n");
if (!expressions.isEmpty()) {
- sb.append(" final int length = value.length();\n");
+ sb.append(" final int length = value.codePointCount(0, value.length());\n");
for (String exp : expressions) {
sb.append(" if (").append(exp).append(") {\n");
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.test.model;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.mdsal661.norev.Foo;
+
+public class Mdsal661Test {
+ @Test
+ public void testLengthEnforcerReject() {
+ assertThrows(IllegalArgumentException.class, () -> new Foo(""));
+ assertThrows(IllegalArgumentException.class, () -> new Foo("ab"));
+ }
+
+ @Test
+ public void testLengthEnforcerAccept() {
+ assertNotNull(new Foo("a"));
+ // U+1F31E, encodes to UTF-16 as "\uD83C\uDF1E", i.e. two code units
+ assertNotNull(new Foo("🌞"));
+ }
+}