Sam Jaffe пре 4 година
родитељ
комит
33952f0dbd

+ 7 - 3
stream.xcodeproj/project.pbxproj

@@ -44,6 +44,7 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
+		CD64CCB926232D6900770A30 /* xcode_gtest_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xcode_gtest_helper.h; sourceTree = "<group>"; };
 		CD9337281E3CD78B00699FF5 /* stream_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = stream_test.cxx; sourceTree = "<group>"; };
 		CDAA170121A3A738007BBA11 /* stream */ = {isa = PBXFileReference; lastKnownFileType = folder; name = stream; path = include/stream; sourceTree = "<group>"; };
 		CDE8545E24DEBEBF006FE7C7 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -89,6 +90,7 @@
 		CD9337371E3CD88200699FF5 /* test */ = {
 			isa = PBXGroup;
 			children = (
+				CD64CCB926232D6900770A30 /* xcode_gtest_helper.h */,
 				CD9337281E3CD78B00699FF5 /* stream_test.cxx */,
 				CDF9374E1E3D9AD7003E5D5C /* stream_fluent_test.cxx */,
 			);
@@ -147,7 +149,7 @@
 		0E5DFDBA1BB4D3190063976E /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 1030;
+				LastUpgradeCheck = 1230;
 				TargetAttributes = {
 					CDEC1D6D23514BC60091D9F2 = {
 						CreatedOnToolsVersion = 11.1;
@@ -249,6 +251,7 @@
 				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
 				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
 				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
 				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
 				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -286,6 +289,7 @@
 				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
 				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
 				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
 				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
 				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -334,7 +338,7 @@
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
 				INFOPLIST_FILE = "stream-test/Info.plist";
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
-				MACOSX_DEPLOYMENT_TARGET = 10.14;
+				MACOSX_DEPLOYMENT_TARGET = 10.15;
 				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.stream-test";
@@ -367,7 +371,7 @@
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
 				INFOPLIST_FILE = "stream-test/Info.plist";
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
-				MACOSX_DEPLOYMENT_TARGET = 10.14;
+				MACOSX_DEPLOYMENT_TARGET = 10.15;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.stream-test";

+ 52 - 0
stream.xcodeproj/xcshareddata/xcschemes/stream-test.xcscheme

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "1240"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+         <TestableReference
+            skipped = "NO">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "CDEC1D6D23514BC60091D9F2"
+               BuildableName = "stream-test.xctest"
+               BlueprintName = "stream-test"
+               ReferencedContainer = "container:stream.xcodeproj">
+            </BuildableReference>
+         </TestableReference>
+      </Testables>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 6 - 6
stream.xcodeproj/xcuserdata/samjaffe.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -5,16 +5,11 @@
 	<key>SchemeUserState</key>
 	<dict>
 		<key>stream-test.xcscheme_^#shared#^_</key>
-		<dict>
-			<key>orderHint</key>
-			<integer>55</integer>
-		</dict>
-		<key>stream_tc.xcscheme</key>
 		<dict>
 			<key>isShown</key>
 			<true/>
 			<key>orderHint</key>
-			<integer>18</integer>
+			<integer>40</integer>
 		</dict>
 	</dict>
 	<key>SuppressBuildableAutocreation</key>
@@ -29,6 +24,11 @@
 			<key>primary</key>
 			<true/>
 		</dict>
+		<key>CDEC1D6D23514BC60091D9F2</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
 	</dict>
 </dict>
 </plist>

+ 1 - 1
test/stream_fluent_test.cxx

@@ -5,7 +5,7 @@
 //  Created by Sam Jaffe on 1/28/17.
 //
 
-#include <gmock/gmock.h>
+#include "xcode_gtest_helper.h"
 
 #include <vector>
 

+ 36 - 1
test/stream_test.cxx

@@ -5,8 +5,9 @@
 //  Created by Sam Jaffe on 1/28/17.
 //
 
-#include <gmock/gmock.h>
+#include "xcode_gtest_helper.h"
 
+#include <map>
 #include <string>
 #include <vector>
 
@@ -26,6 +27,14 @@ TEST(StreamTest, IteratorPreservesElements) {
   EXPECT_THAT(out, Eq(input));
 }
 
+TEST(MapStreamTest, IteratorPreservesElements) {
+  std::map<int, int> input{{1, 1}, {2, 2}};
+  auto s = stream::make_stream(input);
+  std::map<int, int> out{s.begin(), s.end()};
+
+  EXPECT_THAT(out, Eq(input));
+}
+
 TEST(StreamTest, CollectPreservesElements) {
   std::vector<int> input{1, 2, 3, 4, 5};
   auto s = stream::make_stream(input);
@@ -60,6 +69,32 @@ TEST(StreamTest, MapCanAlterValues) {
   EXPECT_THAT(s.collect(), Eq(expected));
 }
 
+template <typename T> struct nocopy {
+  T value;
+  nocopy(T const & val) : value(val) {}
+  nocopy(nocopy const &) = delete;
+  nocopy & operator=(nocopy const &) = delete;
+  nocopy(nocopy &&) = default;
+  nocopy & operator=(nocopy &&) = default;
+
+  operator T() const { return value; }
+};
+
+TEST(MapStreamTest, MapToValue) {
+  auto const input = []() {
+    std::map<int, nocopy<int>> tmp;
+    tmp.emplace(0, 1);
+    tmp.emplace(2, 2);
+    return tmp;
+  }();
+  auto fmap = [](auto & pair) -> auto & { return pair.second; };
+  auto s = stream::make_stream(input).map(fmap);
+  std::vector<int> out(s.begin(), s.end());
+  std::vector<int> const expected{1, 2};
+
+  EXPECT_THAT(out, Eq(expected));
+}
+
 TEST(StreamTest, CanBuildFromSingleElement) {
   int value = 11;
   auto even = [](int i) { return i % 2 == 0; };

+ 38 - 0
test/xcode_gtest_helper.h

@@ -0,0 +1,38 @@
+//
+//  xcode_gtest_helper.h
+//  tax-calculator-test
+//
+//  Created by Sam Jaffe on 11/25/20.
+//  Copyright © 2020 Sam Jaffe. All rights reserved.
+//
+
+#pragma once
+
+#if defined(__APPLE__)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#pragma clang diagnostic pop
+
+#if defined(TARGET_OS_OSX)
+// This is a hack to allow XCode to properly display failures when running
+// unit tests.
+#undef EXPECT_THAT
+#define EXPECT_THAT ASSERT_THAT
+#undef EXPECT_THROW
+#define EXPECT_THROW ASSERT_THROW
+#undef EXPECT_ANY_THROW
+#define EXPECT_ANY_THROW ASSERT_ANY_THROW
+#undef EXPECT_NO_THROW
+#define EXPECT_NO_THROW ASSERT_NO_THROW
+#undef EXPECT_TRUE
+#define EXPECT_TRUE ASSERT_TRUE
+#undef EXPECT_FALSE
+#define EXPECT_FALSE ASSERT_FALSE
+
+#endif
+#endif