Skip to content

Commit

Permalink
use possesive quantifier
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Aug 18, 2023
1 parent f9f81f9 commit dfcb961
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit dfcb961

Please sign in to comment.