<commit_before>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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.eclipse.xtext.crossrefs;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import org.eclipse.xtext.util.StringInputStream;

/**
 * @author <NAME> - Initial contribution and API
 *
 */
public class DefaultScopeProviderTest extends AbstractGeneratorTest {
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		with(ImportUriTestLanguageStandaloneSetup.class);
	}
	
	public void testSimple() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar");
		models.addModel("bar.importuritestlanguage", "type bar");
		
		Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
	}
	
	public void testScope() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
		models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar");
		
		Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
		assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
		assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
		assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
	}<commit_msg>added tests for bug  https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879<commit_after>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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.eclipse.xtext.crossrefs;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import org.eclipse.xtext.util.StringInputStream;

/**
 * @author <NAME> - Initial contribution and API
 *
 */
public class DefaultScopeProviderTest extends AbstractGeneratorTest {
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		with(ImportUriTestLanguageStandaloneSetup.class);
	}
	
	public void testSimple() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar");
		models.addModel("bar.importuritestlanguage", "type bar");
		
		Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
	}
	
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
	public void testRelativeScope() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("testfile://my/folder/foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
		models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
		
		Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
		assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
		assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
		assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
	}
	
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
	public void testRelativeScopeWithPath() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		models.addModel("testfile://my/folder/foo.importuritestlanguage", "import './../folder/bar.importuritestlanguage' type foo extends bar type bar extends bar2");
		
		models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
		
		Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
		assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
		assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
		assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
	}
	
	public void testScopeFileName() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
		models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar");
		
		Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
		
		assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
		assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
		assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
		assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
	}
	
	// TODO: report a meaningful error to the user when resolving of an import fails
	
	/*
	public void testUnresolvableImport() throws Exception {
		TestURIConverter models = new TestURIConverter();
		ResourceSetImpl rs = new ResourceSetImpl();
		rs.setURIConverter(models);
		
		models.addModel("testfile://my/folder/foo.importuritestlanguage", "import <unknownfile.importuritestlanguage> type foo extends bar type bar extends bar2");
		
		Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
	}
	*/
{'fraction_non_alphanumeric': 0.1730164717716585, 'fraction_numerical': 0.008173016471771658, 'mean_word_length': 5.928571428571429, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 3, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2021493', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2297, 'n_words': 465}