From dfcb9614e5fef12b367fe1ccbf3cffef1c63c4c5 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 2 Aug 2023 13:14:29 +0200 Subject: [PATCH] use possesive quantifier --- .../fuse/mount/AbstractMountBuilder.java | 3 +- .../fuse/mount/AbstractMountBuilderTest.java | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilderTest.java diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilder.java b/src/main/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilder.java index 96d6637..37c7cd1 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilder.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilder.java @@ -29,9 +29,10 @@ public MountBuilder setMountpoint(Path mountPoint) { @Override public MountBuilder setMountFlags(String mountFlagsString) { + var mfs = " "+mountFlagsString.trim(); // we assume that each flag starts with "-" var notEmpty = Predicate.not(String::isBlank); - this.mountFlags = Pattern.compile("\\s+-").splitAsStream(" "+mountFlagsString).filter(notEmpty).map("-"::concat).collect(Collectors.toUnmodifiableSet()); + this.mountFlags = Pattern.compile("\\s++-").splitAsStream(mfs).filter(notEmpty).map("-"::concat).collect(Collectors.toUnmodifiableSet()); return this; } diff --git a/src/test/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilderTest.java b/src/test/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilderTest.java new file mode 100644 index 0000000..fd72360 --- /dev/null +++ b/src/test/java/org/cryptomator/frontend/fuse/mount/AbstractMountBuilderTest.java @@ -0,0 +1,45 @@ +package org.cryptomator.frontend.fuse.mount; + +import org.cryptomator.integrations.mount.Mount; +import org.cryptomator.integrations.mount.MountFailedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import java.nio.file.Path; +import java.util.Arrays; + +public class AbstractMountBuilderTest { + + TestMountBuilder inTest = new TestMountBuilder(); + + @ParameterizedTest + @CsvSource(textBlock = """ + -asd,-asd + -asd\t-qwe,-asd;-qwe + -asd ,-asd + -abc qwe,-abc qwe + \t -foo file/to/use -bar 4 -b az not,-foo file/to/use;-bar 4;-b az not + """) + public void testSetMountFlags(String toTest, String expectedRaw) { + var expected = Arrays.stream(expectedRaw.split(";")); + + inTest.setMountFlags(toTest); + expected.forEach( exp -> Assertions.assertTrue(inTest.mountFlags.contains(exp))); + } + + + class TestMountBuilder extends AbstractMountBuilder { + + public TestMountBuilder() { + super(Path.of("abc")); + } + + @Override + public Mount mount() throws MountFailedException { + return null; + } + } +}